基于SpringBoot的海洋环保小程序系统(毕业设计项目源码+文档)
2025/12/25 23:41:22
就是编写一个类,在这个类上面使用大量注解来代替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();}执行结果如下: