简体   繁体   中英

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.

在此处输入图片说明

after commenting all code related to AspectJ, the bugs disappears and the transaction is working perfectly, but i'm missing my AspectJ functions.

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.

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不能很好地配合使用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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