简体   繁体   English

Spring MVC 到 SpringBoot 2:bean 'xyz' 无法作为 'com..Abc' 注入,因为它是一个 JDK 动态代理,它实现:

[英]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.

相关问题 无法将 bean 作为“类型”注入,因为它是一个 JDK 动态代理,它实现了:reactor.fn.Consumer - The bean could not be injected as a 'Type' because it is a JDK dynamic proxy that implements: reactor.fn.Consumer Spring 引导:无法将 bean 'auditLogDao' 作为 'AuditLogDao' 注入,因为它是 JDK 动态代理 - Spring Boot: The bean 'auditLogDao' could not be injected as a 'AuditLogDao' because it is a JDK dynamic proxy Spring请求范围bean代理bean无法注入 - Spring request scope bean proxy bean can not be injected 动态注入 JDK 动态代理作为 spring bean - 但前提是没有其他实现可用 - Dynamically injecting a JDK dynamic proxy as spring bean - but only if no other implementation is available 为什么在Spring AOP中,对象被包装到实现接口的JDK代理中? - Why in Spring AOP the object are wrapped into a JDK proxy that implements interfaces? 在Spring配置文件中的bean属性中覆盖属性值$ {abc.xyz} - override property value ${abc.xyz} in bean property in spring configuration file Spring JDK动态代理和CGLIB - 实现细节 - Spring JDK Dynamic Proxy and CGLIB - implementation details 由于JDK代理,导致UnsatisfiedDependencyException异常 - UnsatisfiedDependencyException because of the JDK proxy 春豆没有注射 - Spring bean not getting injected com.abc.serive.MysqlService 中的字段 countRepo 需要一个无法找到的“com.abc.repository.ClicksQuickReplyRepository”类型的 bean - Field countRepo in com.abc.serive.MysqlService required a bean of type 'com.abc.repository.ClicksQuickReplyRepository' that could not be found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM