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

后端 未结 9 2054
走了就别回头了
走了就别回头了 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

    I had the same problem:

    This is just a guess, but try making an interface InnerThreadInterface, then let InnerThread class extend it. After that you should be able to do:

    I use this way instead of what is posted above and it worked fine. There was no need of setting the proxy-target-class to true, this required more libraries that wasn't on my classpath.

    InnerThreadInterface inner = (InnerThreadInterface)ctx.getBean("innerThread");
    

提交回复
热议问题