简体   繁体   English

在Spring Boot中配置事务后,AspectJ无法正常工作

[英]AspectJ not working after Transaction configuration in Spring Boot

Firstly i had a problem with Transactions not working so i updated the configutation from @EnableTransactionManagement to @EnableTransactionManagement(proxyTargetClass=true) , but after the update this bug is thrown at launch. 首先,我遇到事务无法正常工作的问题,因此我将配置从@EnableTransactionManagement更新为@EnableTransactionManagement(proxyTargetClass=true) ,但是在更新后,此错误在启动时抛出。

在此处输入图片说明

after commenting all code related to AspectJ, the bugs disappears and the transaction is working perfectly, but i'm missing my AspectJ functions. 在注释了与AspectJ相关的所有代码之后,这些错误消失了,并且事务运行正常,但是我缺少了AspectJ函数。

i've tried to replace @EnableTransactionManagement(proxyTargetClass=true) by @EnableTransactionManagement(mode=AdviceMode.PROXY) and by @EnableTransactionManagement @EnableLoadTimeWeaving , none of them let me use AspectJ, using the debugger i can see that the advice is not executed at all. 我试图用@EnableTransactionManagement(mode=AdviceMode.PROXY)@EnableTransactionManagement @EnableLoadTimeWeaving替换@EnableTransactionManagement(proxyTargetClass=true)@EnableTransactionManagement @EnableLoadTimeWeaving ,它们都没有让我使用AspectJ,使用调试器我可以看到建议没有执行完全没有

AppConfig.java AppConfig.java

@EnableAutoConfiguration
@ComponentScan(basePackages = { "com.geopro" })
@EnableJpaRepositories(basePackages = { "com.geopro.repositories" })
@EntityScan(basePackages = { "com.geopro.entities" })
@EnableTransactionManagement(proxyTargetClass=true)//(mode=AdviceMode.ASPECTJ)//
public class AppConfig {
    @Bean
    public HibernateJpaSessionFactoryBean sessionFactory(EntityManagerFactory emf) {
         HibernateJpaSessionFactoryBean factory = new HibernateJpaSessionFactoryBean();
         factory.setEntityManagerFactory(emf);
         return factory;
    }
}

故事的寓意是, 永远不要在同一个类中混合使用Transaction和AspectJ函数 ,我了解到,Transaction在其内部AOP中使用的困难方式是,其AOP与用户AOP不能很好地配合使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM