sprinboot 整合shiro后, aop不生效

2,682 阅读1分钟

以下是我遇到的问题,从下午4点解决到晚上10点终于解决了

`

Description:
The bean 'orderGoodsService' could not be injected as a 'com.xxx.OrderGoodsService' because it is a JDK dynamic proxy that implements:

Action:

Consider injecting the bean as one of its interfaces or forcing the use of CGLib-based proxies by setting proxyTargetClass=true on @EnableAsync and/or @EnableCaching.
Process finished with exit code 1

`

解决方案一

spring.aop.auto=true spring.aop.proxy-target-class: true

解决方案二

@EnableTransactionManagement(proxyTargetClass = true)

尝试以上方案都没解决

项目有两个模块(admin-api、wx-api),发现只有wx-api可以正常启动,admin-api不可以会报以上错误

经过对比发现,admin-api模块比wx-api多shiro-spring-boot-starter

终极解决方案

`

@Bean
@DependsOn("lifecycleBeanPostProcessor")
public static DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
    DefaultAdvisorAutoProxyCreator creator = new DefaultAdvisorAutoProxyCreator();
    //这一句比较重要
    creator.setProxyTargetClass(true);
    return creator;

    
}

`