新建Spring项目

新建流程

屏幕快照 2017-03-07 下午10.50.09

屏幕快照 2017-03-07 下午10.51.48

完成至以上目录结构

代码

Main.java

package com.imekaku;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created by lee on 2017/3/7.
 */
public class Main {
    public static void main(String[] args) {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationConfigure.xml");
        HelloWorld helloWorld = (HelloWorld) ctx.getBean("helloworld");
        System.out.println(helloWorld);
    }
}

HelloWorld.java

package com.imekaku;

/**
 * Created by lee on 2017/3/7.
 */
public class HelloWorld {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    HelloWorld () {
        System.out.println("HelloWorld Constructor");
    }
}

applicationConfigure.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id = "helloworld" class="com.imekaku.HelloWorld"></bean>
</beans>

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

开始在上面输入您的搜索词,然后按回车进行搜索。按ESC取消。

返回顶部