spring框架的最小集合:
(1)
(2)引入的包见附件
(3)将spring-config.xml放在src下
(4)测试:bean
test--main
(1)
spring-config.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-2.5.xsd" >
<bean id="aa" class="com.test0117.Person"></bean>
</beans>
(2)引入的包见附件
(3)将spring-config.xml放在src下
(4)测试:bean
package com.test0117;
public class Person {
private String name="qq";
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
test--main
package com.test0117;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestSpring {
public static void main(String[] args) {
AbstractApplicationContext app = new ClassPathXmlApplicationContext(
"spring-config.xml");
Person p = (Person) app.getBean("aa");
System.out.println(p.getName());
}
}