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 ...
随机推荐
- leetcode 1541. 平衡括号字符串的最少插入次数
问题描述 给你一个括号字符串 s ,它只包含字符 '(' 和 ')' .一个括号字符串被称为平衡的当它满足: 任何左括号 '(' 必须对应两个连续的右括号 '))' . 左括号 '(' 必须在对应的连 ...
- 【刷题-LeetCode】300. Longest Increasing Subsequence
Longest Increasing Subsequence Given an unsorted array of integers, find the length of longest incre ...
- 【小记录】解决链接libcufft_static.a库出现的错误
程序中使用了 cv::cuda::dft() 函数,需要在链接的时候使用libcufft_static.a这个库.链接出现大量类似错误:error: undefined reference to __ ...
- Solon 1.6.18 发布,轻量级应用开发框架
关于官网 千呼万唤始出来: https://solon.noear.org .整了一个月多了...还得不断接着整! 关于 Solon Solon 是一个轻量级应用开发框架.支持 Web.Data.Jo ...
- default和delete
在C++中,有四类特殊的成员函数,分别为:默认构造函数,默认析构函数,默认拷贝构造函数,默认赋值运算符.他们的作用为创建.初始化.销毁.拷贝对象. 虽然在类A中什么都没有定义,但是编译会通得过,因为编 ...
- gin使用BasicAuth中间件
package mainimport ( "github.com/gin-gonic/gin" "net/http")// 模拟一些私人数据var secret ...
- 使用du与df命令查看磁盘容量不一致
在Linux系统的ECS实例中,执行du与df命令查看磁盘容量,出现不一致的现象 执行df -h命令查看文件系统的使用率,可以看到500G 执行du / -sh 命令只使用250G 执行du和df命令 ...
- Java多线程基础-ThreadLocal
感谢原文作者:Yuicon 原文链接:https://segmentfault.com/a/1190000016705955 序 在多线程环境下,访问非线程安全的变量时必须进行线程同步,例如使用 sy ...
- JS 中的GB2312转UTF8和UTF8转GB2312
转载请注明来源:https://www.cnblogs.com/hookjc/ JS:encodeURI encodeURI(URIString)必选的 URIString 参数代表一个已编码的 UR ...
- bom-setInterval
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...