Spring Boot 自定义配置文件异常"expected single matching bean but found 2"
运行环境:Spring Boot 2.5.0, IDEA 2020.3.2
异常详细信息:
Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'com.example.demo.config.MyConfigProperties'
available: expected single matching bean but found 2: myConfigProperties,test-com.example.demo.config.MyConfigProperties
一开始是这样写的
@Configuration
@PropertySource("classpath:myConfig.properties")
@ConfigurationProperties(prefix = "test")
@Component
@Data
public class MyConfigProperties {
private String name;
private int age;
}
@SpringBootApplication
@EnableConfigurationProperties(MyConfigProperties.class)
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
@RestController
public class IndexController {
@Resource
private MyConfigProperties myConfig;
@RequestMapping("/config")
String customConfig() {
String name = myConfig.getName();
return name + myConfig.getAge();
}
}
Spring Boot 自定义配置文件异常"expected single matching bean but found 2"的更多相关文章
- 深入Spring Boot:怎样排查expected single matching bean but found 2的异常
写在前面 这个demo来说明怎么排查一个常见的spring expected single matching bean but found 2的异常. https://github.com/hengy ...
- spring依赖注入单元测试:expected single matching bean but found 2
异常信息:org.springframework.beans.factory.UnsatisfiedDependencyException: Caused by: org.springframewor ...
- spring " expected single matching bean but found 2" 问题一例。
初入java,使用spring时遇到一个问题,左边是一个接口和实现.右边是service和实现. @Service@Transactional(rollbackFor = Exception.clas ...
- Spring 3.2 @Autowired异常:expected single matching bean but found 2
在使用Sping做单元测试时候,对RequestMappingHandlerAdapter(从处理器包装过来的适配器)进行自动装配, 发现报:expected single matching bean ...
- 多个@bean无法通过@resource注入对应的bean(org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected single matching bean but found )
一.异常 org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type ' ...
- expected single matching bean but found 2
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'acc ...
- 多数据源报错 expected single matching bean but found 2: xxx,xxx
问题: expected single matching bean but found 2: xxx,xxx 原因:在 Spring 容器中配置了两个类型Bean,Spring 容器将无法确定到底要用 ...
- MyBatis Plus:No qualifying bean of type 'com.baomidou.mybatisplus.mapper.BaseMapper<?>' available: expected single matching bean but found 4
场景: 应用MyBatis Plus 和通用Mapper 继承自ServiceImpl实现对Service里的方法进行包装再处理. public interface IServiceBase2< ...
- spring boot自定义配置文件
把一些可能会经常变动的东西写在配置文件中,可以增加程序的灵活性,避免多次改版发版. 在sping boot中除了自带的默认配置文件application.properties之外,我们还可以在reso ...
随机推荐
- MySQL提权之mof提权
mof提权原理 关于 mof 提权的原理其实很简单,就是利用了 c:/windows/system32/wbem/mof/ 目录下的 nullevt.mof 文件,每分钟都会在一个特定的时间去执行一次 ...
- 拉普拉斯平滑(Laplacian smoothing)
概念 零概率问题:在计算事件的概率时,如果某个事件在观察样本库(训练集)中没有出现过,会导致该事件的概率结果是 $0$ .这是不合理的,不能因为一个事件没有观察到,就被认为该事件一定不可能发生(即该 ...
- 知乎上一个关于Android面试的问题答案
由于链接出错,这里附上原文链接:Touch Me 前段时间面试,自己以及小伙伴们简要的汇总的一些面试问题,可以对照的参考一下吧- 建议就是在面一家公司之前了解好这个公司的app是以什么为驱动的,例如电 ...
- 《剑指offer》面试题40. 最小的k个数
问题描述 输入整数数组 arr ,找出其中最小的 k 个数.例如,输入4.5.1.6.2.7.3.8这8个数字,则最小的4个数字是1.2.3.4. 示例 1: 输入:arr = [3,2,1], k ...
- [CAN波形分析] 一次CAN波形分析之旅
Prepare CAN通信协议使用了有一段时间了,但都是基于软件层面的使用,对于其波形不是很了解,正好这段时间比较闲,是时候补补硬知识. 开始之前,先介绍一下设备: 咸鱼淘来的古董级别示波器GDS-2 ...
- 【转载】select case break引发的血案
原文请看:select case break引发的血案 我也遇到了,浪费了一个多小时. 牢记: for { switch var1{ case "not match": go En ...
- 微服务架构 | 2.2 Alibaba Nacos 的统一配置管理
目录 前言 1. Nacos 配置中心基础知识 1.1 Nacos 在配置中心中的功能 1.2 Nacos 配置管理 Data ID 的构成 1.3 Nacos 配置的回滚机制 1.4 Nacos 配 ...
- 学习鸟哥私房菜--linux bash 的环境变量ps1设置
bash里边的变量ps1是用户平时的提示符,系统默认为[username@host 工作目录]$.关于ps1的相关介绍详见:http://www.cnblogs.com/starspace/archi ...
- 华为联运游戏审核驳回:在未安装或需更新HMS Core的手机上,提示安装,点击取消后,游戏卡屏(集成的6.1.0.301版本游戏SDK)
问题描述 更新游戏SDK到6.1.0.301版本之后,游戏包被审核驳回:在未安装或需更新华为移动服务版本(HMS Core)的手机上,提示安装华为移动服务(HMS Core),点击取消,游戏卡屏.修改 ...
- 直接copy大于某一个时间小于某一个时间的文件--find进阶用法
find ./ -type f -newermt '2000-01-04 10:30:00' ! -newermt '2019-10-28 10:57:00' -exec cp -a {} /var/ ...