我在 multimodule maven
项目中有 2 个 SpringBoot
Apps
。在第一个 Spring Boot 应用程序中,我使用 Spring AOP
实现了注释。我如何在我的第二个 Spring 应用程序中使用带有方面逻辑的注释
?
最佳答案
您需要将 AOP Spring Boot 应用程序作为第二个应用程序的依赖项包含在内。这将使您能够访问注释。
在您的 AOP Spring Boot 应用程序中创建一个 @Configuration
类,用于启用 AOP 并扫描您的方面。
@Configuration
@ComponentScan("package.of.aspects")
@EnableAspectJAutoProxy
public class AopConfig() {
}
有多种方法可以在辅助应用程序中启用此配置。
最简单的一种是使用@Import
注释:
@Import(AopConfig.class)
@SpringBootApplication
public class SecondApplication {
...
}
您还可以通过创建包含以下内容的 AopSpringBoot/src/main/resources/META-INF/spring.factories
文件来使 AopConfig
成为自动配置:
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
fully.qualified.name.AopConfig
关于java - 如何使用其他 SpringBoot 项目的注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59585476/