Spring Lookup方法注入由于AbstractMethodError失败 [英] Spring Lookup Method Injection failing with AbstractMethodError

查看:56
本文介绍了Spring Lookup方法注入由于AbstractMethodError失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似于以下的单例服务类。

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类:

ContextProvider class:

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

配置:

<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" />

当我尝试使用Junit运行以上命令时->而不是按需创建查找bean正在收到以下错误

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:
用途:java.lang.AbstractMethodError
在org.springframework .beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1585)
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
在org.springframework .beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)

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

推荐答案

我找到了问题并解决了。

I found the issue and fixed it.

我正在实现抽象类接口。因此,在运行时,由于存在未实现的方法,
CGLIB无法创建代理类。

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.

我删除了 implements,它运行正常。

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.

这篇关于Spring Lookup方法注入由于AbstractMethodError失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆