我是新來的春天,並試圖使用@Autowire註釋從服務層(@服務)彈簧自動裝配與ibatis的
這裏我DAOImpl類(@Repository)是我的代碼:
@Service
public class DefaultLocationService implements LocationService
{
@Autowired
@Qualifier("countryDao")
private CountryDAO countryDao; // This is an interface
public void setCountryDao(CountryDAO countryDao) {
this.countryDao = countryDao;
}
// More code
}
然後我有CountryDaoImpl類(@Repository),它實現了CountryDAO
@Repository("countryDao")
public class CountryDAOImpl extends InstrumentedSqlMapDaoTemplate implements CountryDAO {
@Autowired
public CountryDAOImpl(DaoManager daoManager) {
super(daoManager);
}
// More code
}
public class InstrumentedSqlMapDaoTemplate extends SqlMapDaoTemplate
{
public InstrumentedSqlMapDaoTemplate(DaoManager daoManager)
{
super(daoManager);
}
// More code
}
發生該問題與SqlMapDaoTemplate,因爲它有一個帶有參數的構造函數,因此Spring可以ñ沒有實例化一個默認構造函數並失敗。對於我在自動裝配我DAOImpl類的構造函數,但仍然沒有運氣,也未能與此異常:
Unsatisfied dependency expressed through constructor argument with
index 0 of type [com.ibatis.dao.client.DaoManager]: : No matching bean
of type [com.ibatis.dao.client.DaoManager] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for
this dependency. Dependency ann otations: {}; nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
matching bean of t ype [com.ibatis.dao.client.DaoManager] found for
dependency: expected at least 1 bean which qualifies as autowire
candid ate for this dependency. Dependency annotations: {}
你們可以請讓我知道我在做什麼錯在這裏。
感謝, 特洛伊
您可以將代碼發佈到您的DaoManager創建的地方嗎? – luboskrnac 2014-10-08 17:29:45
也請發表你的Spring上下文配置。你使用的是Java還是XML配置? – luboskrnac 2014-10-08 17:30:53