简体   繁体   中英

Unable to create a bean for a service class present inside a jar

I have a Spring Boot project where I have an external dependency jar. In that jar there is an interface as below:

public interface Feature {

  List<FeatureResponse> getFeatures(FeatureRequest req);

}

Its implementation is:

@Service
public class FeatureImpl implements Feature {

    public List<FeatureResponse> getFeatures(FeatureRequest featureReq) {
        // do something
        return featureList;
    }
}

Now in my Spring Boot project inside one my class I have used the request and response to object the feature list. However, though it compiles, it fails to run. The error is simple bean creation error at the injection point of Autowired that we get. Below is my class:

@Component
public class FeatureServiceImpl implements featureService { 

    @Autowired
    Feature feature;

    -----

}

The injection with @Autowired is not happening here.

In your configuration class or your SpringBootApplication class add the following

@ComponentScan({"base.package.of.your.currentJar","base.package.of.your.ImportedJar"})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM