Fixing BeanNotOfRequiredTypeException on Spring proxy cast on a non-singleton bean?

后端 未结 9 1998
走了就别回头了
走了就别回头了 2020-12-05 06:59

I\'m having an issue with pulling a Spring bean from an application context.

When I try;

InnerThread instance = (InnerThread) SpringContextFactory.g         


        
相关标签:
9条回答
  • 2020-12-05 07:49

    There was this problem until I just restart Idea and rebuilt the Maven project.

    0 讨论(0)
  • 2020-12-05 07:51

    Another way to handle this problem would be to implement an interface and request the interface from spring, the proxy would fully implement the interface, and the cast shouldn't have a problem.

    0 讨论(0)
  • 2020-12-05 07:52

    Annotate your @Configuration class with

    @EnableAspectJAutoProxy(proxyTargetClass = true) 
    

    You also have to add the following dependency:

    <dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjweaver</artifactId>
    <version>1.7.2</version>
    </dependency> 
    
    0 讨论(0)
提交回复
热议问题