4

I have 2 services, EFT and Cheque that are substantially similar.

Runs fine if I mark the implementation as @service.

Otherwise I get a no such bean definition exception. No qualifying bean of type 'EftPaymentService'.

Top level interface.

public interface PaymentService { public void paymentsResponse(); } 

Eft service interface.

@Service public interface EftPaymentService extends PaymentService { public void processEft(String code) throws PaymentsException; } 

Cheque service interface

@Service public interface ChequePaymentService extends PaymentService { public void processCheque(String code) throws PaymentsException; } 

Top level implementation

public abstract class PaymentServiceImpl implements PaymentService { @Autowired protected SessionFactory sftpSessionFactory; @Autowired protected SftpConfig.UploadGateway gateway; public void paymentsResponse(){ } } 

Eft implementation

public class EftServiceImpl extends PaymentsServiceImpl implements EftPaymentService { } 

Cheque implementation

public class ChequeServiceImpl extends PaymentsServiceImpl implements ChequePaymentService { } 

What is going on here? Refactor using composition?

4
  • Did you check in the logs to see if the implementation class was scanned? Commented Nov 28, 2017 at 2:32
  • Marking the implementation as @Service is what you should do, what exactly is the problem? Commented Nov 28, 2017 at 2:39
  • Is it? stackoverflow.com/questions/16351780/… Commented Nov 28, 2017 at 2:42
  • Yes, it is. You found the question now all that's left is read the answers and understand them. Commented Nov 28, 2017 at 2:53

1 Answer 1

3

Annotate implementations with @Service & use constructor-based injection.

Sign up to request clarification or add additional context in comments.

2 Comments

This works. Have been annotating the services on the basis that referencing the interface is more generic. It doesn't work in this case, although I still don't quite know why.
@Service is just a specialization of @Component; they behave exactly the same. By its name, the former communicates some additional intent. I believe the intent of @Component (thus @Service) it to annotate Spring "bean" implementations, which are typically concrete classes, not interfaces. I guess I'm saying I wouldn't expect putting it on an interface to ever work. Good luck.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.