(37)全注解式开发AOP

(37)全注解式开发AOP

就是编写一个类,在这个类上面使用大量注解来代替spring的配置文件,spring配置文件消失了,如下:

packagecom.powernode.spring6.service;importorg.springframework.context.annotation.ComponentScan;importorg.springframework.context.annotation.Configuration;importorg.springframework.context.annotation.EnableAspectJAutoProxy;@Configuration@ComponentScan("com.powernode.spring6.service")@EnableAspectJAutoProxy(proxyTargetClass=true)publicclassSpring6Configuration{}

测试程序也变化了:

@TestpublicvoidtestAOPWithAllAnnotation(){ApplicationContextapplicationContext=newAnnotationConfigApplicationContext(Spring6Configuration.class);OrderServiceorderService=applicationContext.getBean("orderService",OrderService.class);orderService.generate();}

执行结果如下: