@EnableAspectJAutoProxy不起作用 [英] @EnableAspectJAutoProxy does not work
问题描述
我正在使用Spring Boot,我想将它与AspectJ一起使用.
I am using Spring Boot, and I would like to use AspectJ with it.
以下作品(当然):
@Aspect
@Component
public class RequestMappingAspect {
@Before("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
public void advice(JoinPoint joinPoint) {
...
}
}
但是,如果删除了@Component
并且 @EnableAspectJAutoProxy
已添加,以下操作无效.
However, if @Component
is removed and @EnableAspectJAutoProxy
is added, the following does not work.
@SpringBootApplication
@EnableSwagger2
@EnableAspectJAutoProxy
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
如何正确启用AspectJ自动代理?
How to enable AspectJ auto proxy correctly?
推荐答案
关于同一件事,我们最终做了类似的事情:
Wondering about the same thing, we ended up doing something similar to this:
@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
注释,这也可以正确连接它们.
可能是这是毫无意义的答复,但是,它说明了我们如何解决问题-而不是问题的实际解决方案.让我知道是否要删除它.
This enabled us to just add the @Aspect
-annotation on the aspects, which also wired them correctly.
Might be that this was a pointless reply, however, it explains how we solved the issue - and not the actual solution to the problem. Let me know if you want this to be deleted.
这篇关于@EnableAspectJAutoProxy不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!