我正在使用Spring-boot创建一个多模块Maven应用程序。我在一个模块中有服务层,在另一个模块中有Web层。我无法启动应用程序,出现以下错误:
The bean 'Service' could not be injected as a 'Service' 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.
尝试使用]注释配置类>
@EnableAsync(proxy-target-class=true) @EnableCaching(proxy-target-class=true) @EnableTransactionManagement(proxy-target-class=true) @EnableAspectJAutoProxy(proxy-target-class=true)
一旦我添加了@PreAuthorize或@Transactional类型的任何注释,应用程序就会停止工作。
该服务未实现任何接口,我希望Spring使用CGLib代理进行自动连接,并从跟踪日志中看到以下内容:
* Adding transactional method 'Service.remove' with attribute: PROPAGATION_REQUIRED,ISOLATION_DEFAULT * Creating implicit proxy for bean 'Service' with 0 common interceptors and 3 specific interceptors. * Creating CGLIB proxy: SingletonTargetSource for target object [Service@17765082]
* Adding transactional method 'Service$$EnhancerBySpringCGLIB$$6f15732.remove' with attribute: PROPAGATION_REQUIRED,ISOLATION_DEFAULT * Creating implicit proxy for bean 'Service' with 0 common interceptors and 2 specific interceptors * Creating JDK dynamic proxy: SingletonTargetSource for target object [Service$$EnhancerBySpringCGLIB$$6f15732@32142479]
自动接线的例外是:
Bean named 'locationService' is expected to be of type 'Service' but was actually of type 'com.sun.proxy.$Proxy202'
这是否意味着Spring将我的服务同时注册为CGLib代理和JDK代理?如果是这样,我如何强制它仅使用CGLib代理?
我正在使用Spring-boot创建一个多模块Maven应用程序。我在一个模块中有服务层,在另一个模块中有Web层。我无法启动应用程序,出现以下错误:The ...
预感解决了问题。 Spring AOP可以正常工作,并且可以按预期使用CGLib代理。问题是一个依赖项,它覆盖了代理。