Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何自动连接继承的Spring服务?_Java_Spring_Inheritance - Fatal编程技术网

Java 如何自动连接继承的Spring服务?

Java 如何自动连接继承的Spring服务?,java,spring,inheritance,Java,Spring,Inheritance,我有两种服务,EFT和支票,它们基本上是相似的 如果我将实现标记为@service,则运行良好 否则我会得到一个没有这样bean定义的异常。没有类型为“EftPaymentService”的合格bean 顶级接口 public interface PaymentService { public void paymentsResponse(); } Eft服务接口 @Service public interface EftPaymentService extends PaymentSe

我有两种服务,EFT和支票,它们基本上是相似的

如果我将实现标记为@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(){
  } 
}
public class EftServiceImpl extends PaymentsServiceImpl implements EftPaymentService {
}
public class ChequeServiceImpl extends PaymentsServiceImpl implements ChequePaymentService {
}
Eft实施

public abstract class PaymentServiceImpl implements PaymentService {
  @Autowired
  protected SessionFactory sftpSessionFactory;

  @Autowired
  protected SftpConfig.UploadGateway gateway;

  public void paymentsResponse(){
  } 
}
public class EftServiceImpl extends PaymentsServiceImpl implements EftPaymentService {
}
public class ChequeServiceImpl extends PaymentsServiceImpl implements ChequePaymentService {
}
支票执行

public abstract class PaymentServiceImpl implements PaymentService {
  @Autowired
  protected SessionFactory sftpSessionFactory;

  @Autowired
  protected SftpConfig.UploadGateway gateway;

  public void paymentsResponse(){
  } 
}
public class EftServiceImpl extends PaymentsServiceImpl implements EftPaymentService {
}
public class ChequeServiceImpl extends PaymentsServiceImpl implements ChequePaymentService {
}
这是怎么回事?
使用组合进行重构?

使用
@Service
注释实现并使用基于构造函数的注入。

您是否检查日志以查看是否扫描了实现类?您应该将实现标记为
@Service
,到底是什么问题?是吗?是的。你现在发现了问题,剩下的就是阅读答案并理解它们。这很有效。已经在引用接口更通用的基础上对服务进行了注释。在这种情况下,它不起作用,尽管我仍然不知道为什么。
@Service
只是
@Component
的一个专门化;他们的行为完全一样。通过它的名字,前者传达了一些额外的意图。我相信
@Component
(因此
@Service
)的目的是注释Spring的“bean”实现,这些实现通常是具体的类,而不是接口。我想我是说,我不希望把它放在一个界面上能工作。祝你好运