【发布时间】:2017-11-28 02:21:30
【问题描述】:
我有 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是你应该做的,究竟是什么问题? -
是的。您现在找到了问题,剩下的就是阅读答案并理解它们。
标签: java spring inheritance