贴上几个类,留作备忘
/**
* <p>Description: </p>
* @author scc
* @since 创建时间:2015年11月2日 下午1:44:05
*/
package test.testdi;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
/**
* <p>Description: </p>
* @author scc
* @since 创建时间:2015年11月2日 下午1:44:05
*/
public class Student {
private Teacher teacher;
private String name;
private Toy toy;
private List<String> list;
private Set<Toy> toys;
private Map<String, Toy> detailtoys;
private Properties properties;
/**
* <p>Description: </p>
* @author scc
* @since 创建时间:2015年11月2日 下午1:50:41
**********************************
*/
public Student() {
// TODO Auto-generated constructor stub
}
public Student(Teacher teacher) {
this.teacher=teacher;
}
public void init(){
System.out.println("init");
}
public void say(){
System.out.println((null==teacher?"":teacher.teach())+"say somthing");
}
public void say2(){
System.out.println(toy.toy()+"========="+ name);
}
public void destory(){
System.out.println("destory");
}
public void say3(){
for (String string : list) {
System.out.println(string);
}
}
public void say4(){
for (Toy toy : toys) {
System.out.println(toy.toy());
}
}
public void say5(){
for(Entry<String, Toy> toy:detailtoys.entrySet()){
System.out.println(toy.getKey()+"========"+toy.getValue().toy());
}
}
public void say6(){
for(Entry<Object, Object> toy:properties.entrySet()){
System.out.println(toy.getKey()+"========"+toy.getValue());
}
}
…………………省略setter和getter………………………
}
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"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<bean id="student" class="test.testdi.Student" init-method="init" destroy-method="destory">
<constructor-arg index="0" ref="teacher"/>
<property name="name" value="张三"/>
<property name="toy" ref="toy"/>
<property name="list">
<list>
<value>1</value>
<value>1</value>
<value>1</value>
<value>1</value>
<value>1</value>
</list>
</property>
<property name="toys">
<set value-type="test.testdi.Toy">
<ref bean="toy"/>
<ref bean="toy"/>
<ref bean="toy"/>
</set>
</property>
<property name="detailtoys">
<map>
<entry key="no1" value-ref="toy"/>
<entry key="no2" value-ref="toy"/>
</map>
</property>
<property name="properties">
<props>
<prop key="no1">haha</prop>
<prop key="no2">heihei</prop>
</props>
</property>
</bean>
<bean id="teacher" class="test.testdi.Teacher"/>
<bean id="toy" class="test.testdi.Toy"/>
<bean id="log" class="test.testdi.Log"/>
<aop:config>
<aop:aspect ref="log">
<aop:pointcut expression="execution(* *.say(..))" id="cutstudent"/>
<aop:before method="before" pointcut-ref="cutstudent"/>
<aop:after method="after" pointcut-ref="cutstudent"/>
</aop:aspect>
</aop:config>
</beans>
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>stu-spring</groupId>
<artifactId>stu-spring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<!-- spring基础 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<!-- spring切面 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>3.2.8.RELEASE</version>
</dependency>
</dependencies>
</project>