春季文檔說,目前接口DI是不可能的。看到這裏:http://www.springbyexample.org/examples/core-concepts-dependency-injection-to-the-rescue.htmlSpring Boot,DI可能使用接口,但在Spring中不可行?
我剛開始使用Spring引導,我做了一個簡單的web應用程序,我用DI使用接口。我無法在網上找到原因。爲什麼Spring Boot在Spring中沒有這個功能!
請幫我理解這個概念。
感謝。
編輯
道Imple。
@Repository
public class AbcDaoImpl implements AbcDaoInt{
@Autowired
JdbcTemplate jdbc;
@Override
public int selectABC(String user, String password){
// some db query
}
DAO接口
@Component
public interface AbcDaoInt{
int selectABC(String user, String password);
}
服務
@Service
public class adapter {
@Autowired
AbcDaoInt abcDao;
public Map<String, Object> abc(String user, String password) {
try{
int abcId = abcDao.selectABC(user, pwd);
}
}
您鏈接的頁面已過時,只是部分正確,完全沒有定義「接口注入」的含義。你也不是這麼說。 Spring Boot使用Spring進行依賴注入,所以問題是沒有意義的。 –
@RishiPandey你能告訴我們一些代碼嗎?你不能做接口注入,因爲你需要一些具體的實現。也許你很迷惑讓我們說@ Autowire接口接口,其中接口是一個接口,但春天將自動裝載它的具體實現 – pezetem
@JBNizet我想從鏈接頁面指出,Spring目前有setter和構造函數依賴注入。而且我知道Spring引導爲DI使用了Spring。可能是我不理解這個概念,但我的問題是有效的。 – RishiPandey