[英]How to autowire Spring services that inherit?
我有2項服務,EFT和Check基本相似。
如果我將實現標記為@service,則運行正常。
否則我得到一個沒有這樣的bean定義異常。 沒有'EftPaymentService'類型的限定bean。
頂級界面。
public interface PaymentService {
public void paymentsResponse();
}
Eft服務界面。
@Service
public interface EftPaymentService extends
PaymentService {
public void processEft(String code) throws PaymentsException;
}
檢查服務界面
@Service
public interface ChequePaymentService extends
PaymentService {
public void processCheque(String code) throws PaymentsException;
}
頂級實施
public abstract class PaymentServiceImpl implements PaymentService {
@Autowired
protected SessionFactory sftpSessionFactory;
@Autowired
protected SftpConfig.UploadGateway gateway;
public void paymentsResponse(){
}
}
Eft實施
public class EftServiceImpl extends PaymentsServiceImpl implements EftPaymentService {
}
檢查實施
public class ChequeServiceImpl extends PaymentsServiceImpl implements ChequePaymentService {
}
這里發生了什么? 重構使用組合?
使用@Service
注釋實現並使用基於構造函數的注入。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.