IDE:IntelliJ IDEA 2017
HelloWord.java
package com.xidian.edu;
public class HelloWorld {
private String name;
public void setName(String name){
this.name=name;
}
public void printName(){
System.out.println("Spring Hello:"+this.name);
}
}applicationContext.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="helloBean" class="com.xidian.edu.HelloWorld">
<property name="name" value="Liang Zhuang" />
</bean>
</beans>AppMain.java
package com.xidian.edu;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class AppMain {
public static void main(String args[]){
ApplicationContext context = new ClassPathXmlApplicationContext(
"applicationContext.xml");
HelloWorld obj = (HelloWorld) context.getBean("helloBean");
obj.printName();
}
}目录结构:
运行结果:
Spring框架整合示例
123

被折叠的 条评论
为什么被折叠?



