Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 286 Vote(s) - 3.37 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"No qualifying bean of type" for JPA repository in Spring Boot

#1
I am implementing Rest API with Spring Boot. Since my entity classes are from a package from another package, I had to specify that with annotation `EntityScan`. Also, I used `EnableJpaRepositories` to specify the package where JPA repository is defined. Here is what my project looks like:

[![enter image description here][1]][1]


//Application.java

@Configuration
@EnableAutoConfiguration
@ComponentScan
@EntityScan("org.mdacc.rists.cghub.model")
@EnableJpaRepositories("org.mdacc.rists.cghub.ws.repository")

In my controller class I had a SeqService object autowired.

//SeqController.java

@Autowired private SeqService seqService;

@RequestMapping(value = "/api/seqs", method = GET, produces = APPLICATION_JSON_VALUE)
public ResponseEntity<List<SeqTb>> getSeqs() {
List<SeqTb> seqs = seqService.findAll();
return new ResponseEntity<List<SeqTb>>(seqs, HttpStatus.OK);
}

`SeqService` is an interface from which I created a Bean class for that `SeqServiceBean`. In the `SeqServiceBean` I autowired the JPA repository:

// SeqServiceBean.java

@Autowired private SeqRepository seqRepository;

@Override
public List<SeqTb> findAll() {
List<SeqTb> seqs = seqRepository.findAll();
return seqs;
}

//SeqRepository.java

@Repository
public interface SeqRepository extends JpaRepository<SeqTb, Integer> {

@Override
public List<SeqTb> findAll();

public SeqTb findByAnalysisId(String analysisId);
}

However the application couldn't start due to the following error:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.mda.rists.cghub.ws.repository.SeqRepository] 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)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]

I don't understand the error. What does it have to do with qualifying bean?


[1]:
Reply

#2
You were scanning the wrong package in your `EnableJpaRepositories`. There is no `org.mdacc.rists.cghub.ws.repository` package. So, use this instead:

@EnableJpaRepositories("org.mda.rists.cghub.ws.repository")
Spring Boot does not require any specific code layout to work, however, there are some best practices that will help you. Check out the [spring boot documentation][1] on best practices of structuring your code.


[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through