I have created a Spring Boot application managed by Maven. I'm retrieving an company's library from our Maven repository.
In this library, we have a service interface, not being annotated with '@Service':
public interface MyService {
//...
}
This service has only one implementation :
public class DefaultMyService implements MyService {
//...
}
This library context is managed the old Spring way (in applicationContext.xml file). I read that normally, Spring Boot is able to find the implementation if there's only one in the scope.
When I try to run "spring-boot:run" on my project, it will fail with the following error :
No qualifying bean of type 'com.pharmagest.saml.SAMLService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
I tried:
@ComponentScan(basePackages={"com.mycompany.web", "com.mycompany.thelibrary.client.*", "com.mycompany.thelibrary.services.*"})
In all cases I just can maven build but can't run the project. Do you have any advice to help me ? thanks!
DefaultMyService
has no @Component
(or @Service
) annotation will not be detected.DefaultMyService
instead of the interface. Spring will not detect anything for you your understanding is wrongJust add a @Bean
to your configuration
@Bean
public DefaultMyService myService() {
return new DefaultMyService();
}
Or import the other libraries applicatiponContext.xml
which is what you probably should do.
@ImportResource("classpath:/applicationContext.xml")
Add this next to the @SpringBootApplication
.