0

I have a scenario where I am running a large enterprise application.

  1. There I have a application without a @SpringBootApplication called XYZ Application.The application is not getting Autowired in ABC application which has @SpringBootApplication which I run in the Intellij.How do I make sure bean is created when I run the application.

Note: I have the jars of XYZ application as a gradle build.There are seperate jars for XYZ-api and XYZ-impl.

// XYZ-api

public interface LocationService{

}

//XYZ-impl

@Service("locationServiceImpl")

public class LocationServiceImpl implements LocationService{

 @Resource 

 CountryDAO countryDAO;

}

//PQR (Some other jar file)

@Component
public class LocaleImpl implements Locale{

@Autowired

public LocationService locationService;

}

The error I get is "nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'localeImpl': Unsatisfied dependency expressed through field 'locationService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'LocationService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations:{@org.springframework.beans.factory.annotation.Autowired(required=true)}"

Also I have tried including the package for XYZ application,It does resolve the issue but the @Resource CountryDAO bean is not injected.Please help.

Ajay K
  • 65
  • 4
  • I think you should update the @SpingBootApplication annotation params to include the classes/packages where to look when scanning for services, as those mentioned are not from your application. – Slimu Dec 12 '20 at 07:08
  • You mean ComponentScan.I tried that the error vanishes and I get the error that @Resouce bean is not injected as a dependency bean – Ajay K Dec 12 '20 at 07:12
  • I think this answers your problem https://stackoverflow.com/questions/50230962/cant-autowire-repository-from-an-external-jar-into-spring-boot-app – Slimu Dec 12 '20 at 07:37

1 Answers1

1

The problem based on the error you shared is that Spring is not able to find the bean LocationService. The reason could be two things:

  1. You specified a qualifier on theLocationServiceImpl (@Service("locationServiceImpl")). Maybe Spring is looking for a wrong kind of bean. Maybe adding qualifier would resolve your issue. (More on Qualifier)
  2. These two classes are on two different package. You didn't share this info but if package location differ you need to tell spring application where to look for it. You could follow this link for more info on this issue.
Horpg
  • 36
  • 2