2014-10-08 134 views
1
失敗

我是新來的春天,並試圖使用@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: {} 

你們可以請讓我知道我在做什麼錯在這裏。

感謝, 特洛伊

+0

您可以將代碼發佈到您的DaoManager創建的地方嗎? – luboskrnac 2014-10-08 17:29:45

+0

也請發表你的Spring上下文配置。你使用的是Java還是XML配置? – luboskrnac 2014-10-08 17:30:53

回答

0

的問題是究竟有消息說什麼。你缺少DaoManager類型的bean。當Spring創建countryDay bean時,它嘗試使用構造函數public CountryDAOImpl(DaoManager daoManager)。但是它也需要(根據你的配置)找到類型爲DaoManager的bean。

只需用@Repository註釋來註釋DaoManager類。

+0

DaoManager是Ibatis提供的接口。如果我沒有錯,這不能用@Repository註釋。 對不起,但這可能不會幫助。 – Troy 2014-10-08 16:14:47