Skip to content
Advertisement

In Spring Boot, Can we add @Service Annotation for Interface? if that interface is not implemented by any class

I created a interface which has not any implementations

JavaScript

Can MyInterface be annotated by @Autowired?

JavaScript

following error displayed when it run

JavaScript

Advertisement

Answer

No you can’t, because Spring tries to instantiate it to create a Bean (@Service), but it’s an Interface, so thats not possible.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement