mvn依赖
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!--<!– 激活组件扫描功能,在包aa.bb及其子包下面自动扫描通过注解配置的组件 –>-->
<!--<context:component-scan base-package="aa.bb"/>-->
<!-- 激活自动代理功能 -->
<aop:aspectj-autoproxy proxy-target-class="true"/>
<!-- 可以注入Zhangsan,也可以注入Lisi-->
<!-- scope: 默认是单例,prototype(多例) -->
<bean id="user" class="aa.bb.ZhangSan" scope="prototype">
<property name="age">
<value>20</value>
</property>
<property name="list">
<list>
<value>a</value>
<value>b</value>
<value>c</value>
</list>
</property>
</bean>
</beans>
main 函数
public class App {
public static void main( String[] args ) {
BeanFactory factory = new ClassPathXmlApplicationContext("spring.xml");
IUser user = (IUser)factory.getBean("user");
user.showAge();
System.out.println(((ZhangSan)user).getList());
}
}
Rule.java
package aa.bb;
import java.util.List;
/**
* Created by fang on 16/9/26.
*/
public class ZhangSan implements IUser {
private int age;
private List list;
public void showAge() {
System.out.println("zhang san: "+age);
}
public void setAge(int age) {
this.age = age;
}
public int getAge() {
return age;
}
public void setList(List list) {
this.list = list;
}
public List getList() {
return list;
}
}