Nidheesh
Nidheesh

Reputation: 4562

Injection of autowired dependencies failed inside a jar file

I have put a jar file under lib folder of my war file. Inside the jar I have some classes with @Autowired fileds. Inside the jar , in the applicationContext xml I have given

<context:component-scan base-package="com.main.java.mypath" />

Code:

package com.main.java.mypath.client;

@Component
public class ServiceProvider {

   @Autowired
   private StoreField storeField;




package com.main.java.mypath.data;
public interface StoreField {
}

Error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceProvider': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.main.java.mypath.data.StoreField com.main.java.mypath.client.ServiceProvider.storeField; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.main.java.mypath.data.StoreField] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

Upvotes: 2

Views: 628

Answers (1)

Vasily Vlasov
Vasily Vlasov

Reputation: 3346

It is not possible to inject the dependency as long as you don't have the implementation for your StoreField interface. Make sure that it is implemented as a class and properly initialized in spring context via xml or annotation.

Upvotes: 3

Related Questions