我如何使用来自其他 SpringBoot 项目的注释
How can I use annotations from other SpringBoot project
我在 multimodule maven
项目中有 2 SpringBoot
Apps
。在第一个 spring 引导应用程序中,我使用 spring AOP
实现了注释。我如何在我的第二个 spring 应用程序中将 annotation
与方面逻辑一起使用?
您需要包含 AOP Spring 引导应用程序作为第二个应用程序的依赖项。这将使您能够访问注释。
在您的 AOP Spring 引导应用程序中创建一个 @Configuration
class 以启用 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
我在 multimodule maven
项目中有 2 SpringBoot
Apps
。在第一个 spring 引导应用程序中,我使用 spring AOP
实现了注释。我如何在我的第二个 spring 应用程序中将 annotation
与方面逻辑一起使用?
您需要包含 AOP Spring 引导应用程序作为第二个应用程序的依赖项。这将使您能够访问注释。
在您的 AOP Spring 引导应用程序中创建一个 @Configuration
class 以启用 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