![](/img/trans.png)
[英]The bean could not be injected as a 'Type' because it is a JDK dynamic proxy that implements: reactor.fn.Consumer
[英]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:
我在 Spring Web MVC 中有一个工作项目。 “A”类是一个抽象类。 “B”类扩展A,“C”类扩展B。C类有以下注释;
@Component
@Primary
直到最近一切都运行良好,我们决定使用 SpringBoot 2。我们已经将我们的项目迁移到 SpringBoot 2,添加了所需的依赖项。 现在,当我运行该项目时,出现此错误;
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.
我已经做了一些挖掘,并在网上找到了一个对我不起作用的通用解决方案。*; **使用任何这些注释;
@EnableAspectJAutoProxy(proxyTargetClass=true)
@EnableAsync(proxyTargetClass=true)
@EnableCaching.(proxyTargetClass=true)
PS我有下面给出的配置类;
EnableAspectJAutoProxy(proxyTargetClass=true)
@Configuration("mySpringConfig")
@ComponentScan(basePackages = { "com.allpackages" }, excludeFilters = {someExcludeFilters})
@Conditional(SomeApiSpringConfigCondition.class)
public class SomeCoreSpringConfig extends ApiWebConfiguration{
}
此外,SpringBoot 入口点如下所示;
@SpringBootApplication(exclude = { SomeClasses})
@EnableWebMvc
public class AppInitializer {
public static void main(String[] args) {
SpringApplication.run(AppInitializer.class, args);
}
}
提前致谢!
经过大量挖掘,通过将以下内容添加到“C”类来使其工作。 @Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
所以我的班级“C”看起来像;
@Component
@Primary
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
class C{}
但是,现在其他类的错误即将到来。 所以我会说,这不是一个可持续的解决方案!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.