admin管理员组

文章数量:1794759

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

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没有修复

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

本文标签: definingActionbeanconfigurationnamed