我在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)
P.S。 我有如下配置类;
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);
}
}
谢谢!
答案 0 :(得分:0)
经过大量的挖掘,通过在“ C”类中添加以下内容来使其正常工作。 @Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
所以我的班级“ C”看起来像这样;
@Component
@Primary
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
class C{}
但是,现在其他班级都出现了错误。所以我要说,这不是一个可持续的解决方案!