@EnableAspectJAutoProxy不起作用
我使用Spring Boot,并且我想使用AspectJ。
以下作品(当然):
@Aspect
@Component
public class RequestMappingAspect {
@Before("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
public void advice(JoinPoint joinPoint) {
...
}
}
但是,如果删除了@Component并添加了@EnableAspectJAutoProxy ,则以下内容不起作用。
@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 -annotation,这些方面也正确地连接了它们。 也许这是一个毫无意义的答复,但是,它解释了我们如何解决问题 - 而不是问题的实际解决方案。 让我知道你是否希望将其删除。
您需要@EnableAspectJAutoProxy用于弹簧配置和@Aspect / @Component注释的组合
@EnableAspectJAutoProxy和基于xml的<aop:aspectj-autoproxy>
链接地址: http://www.djcxy.com/p/48705.html