Reputation: 897
What does it take, or is it even possible for Spring to scan and inject non-spring annotated classes? For example.
resource.jar
com.project.resource.ResourceInterface
com.project.resource.StandardResource <-- concrete implementation
@Singleton <--- Standard CDI annotation
public class StandardResource implements ResourceInterface{
@Override
public void something(){}
}
Now let's say I have a spring boot application which depends on resource.jar
.
com.project.resource.SpringApp
@SpringBootApplication(scanBasePackages = {"com.project"})
@EnableAutoConfiguration
public class SpringApp{
... initializer
@Inject
private ResourceInterface resourceService; <--- this is not found
}
Is this supposed to work out of the box? Is this even possible? I'm using spring boot 2.0.0.RELEASE
. I'm getting the following error:
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'MainController': Unsatisfied dependency expressed through field 'resourceService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.project.resource.ResourceInterface' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.inject.Inject()}
Thanks
Upvotes: 0
Views: 1051
Reputation: 1050
For Spring framework @Singleton
has no meaning, as such even if class is picked up by component scanning it's going to be ignored. In order for Spring to recognize your class you can:
@Bean
ofResourceInterface
and instantiate it as StandardResource
. After that your spring boot app will run normally
Upvotes: 2