Spring Lookup Method Injection failing with AbstractMethodError

醉酒当歌 提交于 2020-02-23 06:54:48

问题


I have a singleton service class like the below.

 @Service
 public class SingletonClass{

 @Autowired
 private ContextProvider provider;

 public Context run(){
 context = provider.createContext();
 updateContext(context)
}

ContextProvider class:

 public abstract class ContextProvider implements MyInterface{
        public abstract Context createContext(); 
}

configuration:

<bean name="provider"
        class="xyz.s.s.ContextProvider" >

        <lookup-method name="createContext"
            bean="someBean" />
</bean>
<bean id="somebean" class="com.x.y.someclass" />
<bean id="singletonService" class="com.x.y.SingletonClass" />

When i try to run the above using Junit ->instead of creating the lookup bean on demand, I am getting the below error

org.springframework.beans.factory.BeanCreationException: aused by: java.lang.AbstractMethodError at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1585) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)

It seems, the lookup method injection is not working in my case


回答1:


I found the issue and fixed it.

I was having the abstract class implemented an interface. So at run time, CGLIB unable to create a proxy class since there are unimplemented methods.

Compiler also did not complain, because this is abstract class and it did not expect us to add all implementations of the interface.

I removed the 'implements ' and it just works fine.

So the contextprovider will become,

public abstract class ContextProvider {
        public abstract Context createContext(); 
}

Posting this message, since people might face same situation.



来源:https://stackoverflow.com/questions/30348280/spring-lookup-method-injection-failing-with-abstractmethoderror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!