简体   繁体   English

没有可用类型的合格 bean:预计至少有 1 个 bean 有资格作为自动装配候选者

[英]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.

相关问题 没有可用类型的合格Bean:预计至少有1个合格为自动装配候选的Bean - No qualifying bean of type available: expected at least 1 bean which qualifies as autowire candidate NoSuchBeanDefinitionException:没有符合类型的合格bean <package> &#39;可用:至少有1个符合自动装配候选条件的bean - NoSuchBeanDefinitionException: No qualifying bean of type '<package>' available: expected at least 1 bean which qualifies as autowire candidate 没有可用的&#39;xxx.dao.AreaDao&#39;类型的合格Bean:预计至少有1个符合自动装配候选条件的Bean - No qualifying bean of type 'xxx.dao.AreaDao' available: expected at least 1 bean which qualifies as autowire candidate NoSuchBeanDefinitionException:没有可用类型的限定bean:预期至少有1个bean有资格作为autowire候选者 - NoSuchBeanDefinitionException: No qualifying bean of type available: expected at least 1 bean which qualifies as autowire candidate 没有可用的“Package.TestDaoRepo”类型的合格 bean:预计至少有 1 个 bean 有资格作为自动装配候选 - No qualifying bean of type 'Package.TestDaoRepo' available: expected at least 1 bean which qualifies as autowire candidate 没有可用的“javax.sql.DataSource”类型的合格 bean:预计至少有 1 个有资格作为自动装配候选者的 bean - No qualifying bean of type 'javax.sql.DataSource' available: expected at least 1 bean which qualifies as autowire candidate 没有可用的“ru.spb.repository.UserRepository”类型的合格 bean:预计至少有 1 个 bean 有资格作为自动装配候选 - No qualifying bean of type 'ru.spb.repository.UserRepository' available: expected at least 1 bean which qualifies as autowire candidate 没有可用类型的合格 bean - 预计至少有 1 个 bean 有资格作为自动装配候选 - No qualifying bean of type available - expected at least 1 bean which qualifies as autowire candidate 没有可用的“java.lang.String”类型的合格 bean:预计至少有 1 个有资格作为自动装配候选者的 bean。 依赖注解: - No qualifying bean of type 'java.lang.String' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: 没有可用的“xxx.xxx.xxx.xxx.MyUserDetailsService”类型的合格 bean:预计至少有 1 个有资格作为自动装配候选者的 bean - No qualifying bean of type 'xxx.xxx.xxx.xxx.MyUserDetailsService' available: expected at least 1 bean which qualifies as autowire candidate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM