抽象类实现接口,怎么在抽象类中注入DAO层?

J2EE 码拜 9年前 (2015-04-05) 1239次浏览 0个评论
 
public abstract class TestAbstractImpl implements ITestApi{
@Autowired
@Qualifier("testDao")    
private ITestDao testDao;

public List get() {
	return testDao.get();
	}
}
用于action调用的service如下
@Service("testAnotherApi")
public TestAnotherApi extends TestAbstractImpl implements ITestAnotherApi {
 
}

当我在action调用testAnotherApi.get()方法的时候就会提示报错,原因是在TestAbstractImpl 中testDao没有注入进去。那么该怎么注入呢,求详细解答?谢谢。

抽象类实现接口,怎么在抽象类中注入DAO层?
5分
TestAbstractImpl 添加@Service试一下
抽象类实现接口,怎么在抽象类中注入DAO层?
30分
这样写没问题,  先确认下 是否存在 @Qualifier(“testDao”)  这么个bean.

如果存在且testAnotherApi 能被实例化,那么testDao理应被注入成功. 

抽象类实现接口,怎么在抽象类中注入DAO层?
5分
引用 2 楼 whos2002110 的回复:

这样写没问题,  先确认下 是否存在 @Qualifier(“testDao”)  这么个bean.

如果存在且testAnotherApi 能被实例化,那么testDao理应被注入成功. 

赞同


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明抽象类实现接口,怎么在抽象类中注入DAO层?
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!