[英]Spring MVC to SpringBoot 2: The bean 'xyz' could not be injected as a 'com..Abc' because it is a JDK dynamic proxy that implements:
I have a working project in Spring Web MVC.我在 Spring Web MVC 中有一个工作项目。 Class 'A' is an abstract class. “A”类是一个抽象类。 Class 'B' extends A and class 'C' extends B. Class C has following annotations; “B”类扩展A,“C”类扩展B。C类有以下注释;
@Component
@Primary
Everything has been working fine until recently, we have decided to go to SpringBoot 2. We have migrated our project to SpringBoot 2, added required dependencies.直到最近一切都运行良好,我们决定使用 SpringBoot 2。我们已经将我们的项目迁移到 SpringBoot 2,添加了所需的依赖项。 Now, when I run the project, I get this error;现在,当我运行该项目时,出现此错误;
Bean named 'c' is expected to be of type 'com..B' but was actually of type 'com.sun.proxy.$Proxy132'
***************************
APPLICATION FAILED TO START
***************************
Description:
The bean 'c' could not be injected as a 'com..B' 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.
I have done some digging and found a common solution online which does not work for me.*;我已经做了一些挖掘,并在网上找到了一个对我不起作用的通用解决方案。*; **Using any of these annotations; **使用任何这些注释;
@EnableAspectJAutoProxy(proxyTargetClass=true)
@EnableAsync(proxyTargetClass=true)
@EnableCaching.(proxyTargetClass=true)
PS I have configuration class as given below; PS我有下面给出的配置类;
EnableAspectJAutoProxy(proxyTargetClass=true)
@Configuration("mySpringConfig")
@ComponentScan(basePackages = { "com.allpackages" }, excludeFilters = {someExcludeFilters})
@Conditional(SomeApiSpringConfigCondition.class)
public class SomeCoreSpringConfig extends ApiWebConfiguration{
}
Also, SpringBoot entry point looks like below;此外,SpringBoot 入口点如下所示;
@SpringBootApplication(exclude = { SomeClasses})
@EnableWebMvc
public class AppInitializer {
public static void main(String[] args) {
SpringApplication.run(AppInitializer.class, args);
}
}
Thanks in advance!提前致谢!
After a lot of digging, got it working by adding following to class "C".经过大量挖掘,通过将以下内容添加到“C”类来使其工作。 @Scope(proxyMode = ScopedProxyMode.TARGET_CLASS) @Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
So my class "C" looks like;所以我的班级“C”看起来像;
@Component
@Primary
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
class C{}
However, now the error is coming for other classe.但是,现在其他类的错误即将到来。 So I would say, not a sustainable solution!所以我会说,这不是一个可持续的解决方案!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.