我如何使用其他SpringBoot项目中的注释

问题描述 投票:0回答:1

我在多模块Maven项目中有2个SpringBoot应用程序。在第一个spring boot应用程序中,我使用spring aop实现了注释。如何在我的第二个Spring应用程序中将该注释与方面逻辑一起使用?

java spring spring-boot maven spring-aop
1个回答
0
投票

您需要将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 {
...
}

您还可以通过在AopConfig目录中使用以下内容创建spring.factories来使META-INF成为自动配置:

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
  full.qualified.AopConfig
© www.soinside.com 2019 - 2024. All rights reserved.