Unable to start server, After updating Spring boot3.
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.sample.fa.repository.NewsRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Description:
Field newsRepository in com.sample.fa.service.NewsService required a bean of type 'com.sample.fa.repository.NewsRepository' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
// code
@Repository
public interface NewsRepository extends JpaRepository<News, Long> {
Optional<News> findById(Long id);
}
I have the same issue:
Field repository in com.lst.lexiconlookup.service.LexiconService required a bean of type 'com.lst.lexiconlookup.repository.LexiconRepository' that could not be found.
The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.lst.lexiconlookup.repository.LexiconRepository' in your configuration.
I am using version 3.0.1 from SpringInitialzer. When I take out @Autowired from service class, I can run but get a Null Pointer:
There was an unexpected error (type=Internal Server Error, status=500). Cannot invoke "com.lst.lexiconlookup.repository.LexiconRepository.findAll()" because "this.repository" is null java.lang.NullPointerException: Cannot invoke "com.lst.lexiconlookup.repository.LexiconRepository.findAll()" because "this.repository" is null
@Repository
public interface LexiconRepository extends JpaRepository<Lexicon, Long>
{
}
@Service
public class LexiconService
{
@Autowired
private LexiconRepository repository;
public List<Lexicon> getAllLexicon()
{
return repository.findAll();
}
}
@RestController
public class LexiconController
{
@Autowired
private LexiconService lexiconService;
@GetMapping("/hello")
@ResponseBody
public String hello()
{
return "HELLO";
}
@GetMapping("/lexiconlookup")
@ResponseBody
public List<Lexicon> retrieveAllLexicon()
{
return lexiconService.getAllLexicon();
}
}
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.