I have a working project in Spring Web MVC. Class 'A' is an abstract class. Class 'B' extends A and class 'C' extends B. Class C has following annotations;
@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. 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;
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;
@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". @Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
So my class "C" looks like;
@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!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.