idea2021.1 Action:Consider defining a bean named ‘Forecast1‘ in your configuration.

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-07-15 19:27:05.477 [main] ERROR org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter - 

***************************
APPLICATION FAILED TO START
***************************

Description:

A component required a bean named 'Forecast' that could not be found.


Action:

Consider defining a bean named 'Forecast' in your configuration.

Disconnected from the target VM, address: '127.0.0.1:55032', transport: 'socket'

背景

好久没有写东西了,最近在做项目中使用的是idea2021.1最新版本,多模块项目开发,启动java应用的时候,出现依赖注入失败的情况

操作

 仔细检查了包路径扫描情况

@SpringBootApplication(scanBasePackages = {"com.milla.study"})

 也检查了被注入类的注解情况

package com.milla.study.service.impl;
@Slf4j
@Service("Forecast")
@ConditionalOnProperty(prefix = "spring.config", name = "enableAlgorithm", havingValue = "true")
public class ForecastServiceImpl implements AlgorithmHandlerService<SymptomParamDTO, PrognosticForecastResponseDTO> {
//伪代码
}

 也检查了引用位置代码

 @Resource(name = "Forecast")
    private AlgorithmHandlerService handlerService;

查了很多资料网上都说是扫描包,注解等问题,

但是经过测试发现,这个时候的同路径只有该类注入失败,而且,idea自带的点击跳转功能是好的,能跳转过去;

这个时候我考虑是不是缓存的问题,重启了idea,但是并不起作用,

这时,我复制了一个能注入的类改个名字,发现是能注入的,此时把该问题定位为类名的问题,果不其然,把名字改成ForecastServiceImpl 又注入失败,

至此,大致解决了这个问题,捣蛋鬼居然是类文件的名字,idea2021.1.3最新版应该存在一些bug没有修复

总结:没有完美的工具,有可能在编程过程中,有这样那样的问题,但未必是自己写错了 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值