我正在使用 Spring Boot,并且我想将 AspectJ 与它一起使用。
以下作品(当然):
@Aspect
@Component
public class RequestMappingAspect {
@Before("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
public void advice(JoinPoint joinPoint) {
...
}
}
然而,如果@Component
被删除并且@EnableAspectJAutoProxy http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/EnableAspectJAutoProxy.html添加后,以下不起作用。
@SpringBootApplication
@EnableSwagger2
@EnableAspectJAutoProxy
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
如何正确启用AspectJ自动代理?
想知道同样的事情,我们最终做了类似的事情:
@EnableAspectJAutoProxy(proxyTargetClass = true)
@Configuration("Main applicationContext")
@ComponentScan(
basePackages = {"com.where.ever"},
excludeFilters = {@ComponentScan.Filter(Aspect.class)})
public class ApplicationConfiguration {
@Bean(autowire = Autowire.BY_TYPE)
public SomeAspect someAspect() {
return Aspects.aspectOf(SomeAspect.class);
}
...
...
}
这使我们只需添加@Aspect
-方面的注释,也正确连接它们。
可能这是一个毫无意义的回复,但是,它解释了我们如何解决问题 - 而不是问题的实际解决方案。如果您希望删除此内容,请告诉我。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)