新建流程
完成至以上目录结构
代码
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>