![](/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.