1.spring 3.0 增加了---->AnnotationConfigApplicationContext初始化容器方法(之前我们常用Applicationcontext 这个摆脱不了xml配置)
2.有了AnnotationConfigApplicationContext---------->增加了@Configuration和@Bean(共同使用)
3.@Configuration等于@Component
4.@Bean等于bean配置方法,同时@Bean方法必须公开,有返回值
5.@Bean的属性有四:1.name;2.initMethod;3.destoryMethod;4.autowire (作用与xml差不多,仅4没有了constructor寻找方法)
6.看以下代码:
组件1:
package test;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
@Configuration
public class person {
@Bean
public person demo() {
System.out.println("人造1号初始化完毕!");
return new person();
}
}
组件2:
package test;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
@Configuration
public class person2 {
@Bean
public person2 demo1() {
System.out.println("人造2号初始化完毕!");
return new person2();
}
}
运行类:
package test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class aac {
public static void main(String[] args) {
AnnotationConfigApplicationContext aac=new AnnotationConfigApplicationContext("test");
}
}
运行结果:
需要注意的是AnnotationConfigApplicationContext aac = new AnnotationConfigApplicationContext("test"); //参数部分是写进包名的,而不像ApplicationContext的classpathxmlapplication("配置文件名");
总结:第一次无需配置进行aop测试,感觉非常好!!!!