[英]No qualifying bean of type available: expected at least 1 bean which qualifies as autowire candidate
Unable to start server, After updating Spring boot3.无法启动服务器,更新 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. com.lst.lexiconlookup.service.LexiconService 中的字段存储库需要找不到类型为“com.lst.lexiconlookup.repository.LexiconRepository”的 bean。
The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true)注入点具有以下注释: - @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:行动:
Consider defining a bean of type 'com.lst.lexiconlookup.repository.LexiconRepository' in your configuration.考虑在您的配置中定义类型为“com.lst.lexiconlookup.repository.LexiconRepository”的 bean。
I am using version 3.0.1 from SpringInitialzer.我使用的是 SpringInitialzer 的 3.0.1 版。 When I take out @Autowired from service class, I can run but get a Null Pointer:当我从服务 class 中取出@Autowired 时,我可以运行但得到一个 Null 指针:
There was an unexpected error (type=Internal Server Error, status=500).出现意外错误(类型=内部服务器错误,状态=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无法调用“com.lst.lexiconlookup.repository.LexiconRepository.findAll()”,因为“this.repository”是 null java.lang.NullPointerException:无法调用“com.lst.lexiconlookup.repository.LexiconRepository.findAll()”,因为“ this.repository" 是 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();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.