我在其他类注入的时候出现以下错误 @Autowired NodeAgentService nodeAgentService; 异常 Description: Field mibService in com.xxx.xxx.controller.SnmpController required a single bean, but 2 were found: - mibServiceImpl: defined in file [F:\xxxx\monitorcenter\target\classes…
Field amqpTemplate in * required a single bean, but 3 were found: Spring Boot 启动的时候报的错 使用Spring Boot1.5.8版本. 系统中使用了amqp组件,同事手写了两个RouteKey的RabbitTamplate的模板,项目中*类中@Autowired了RabbitTamplate. 然后就报了这个错,意思是找到了3个模板,不知道自动注入哪一个,建议: Consider marking one of th…
重构遇到个小问题,记录下: 错误信息: *************************** APPLICATION FAILED TO START *************************** Description: Field xxxService in com.alibaba.xxx required a single bean, but 2 were found: 解决方法: Action: Consider marking one of the beans as @Pri…
在学习使用 mybatis-plus 时,遇到一个奇怪的异常 如 代码一: 代码一: Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2019-07-17 09:16:28.739 ERROR 9800 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *****…
@Autowired注解是spring用来支持依赖注入的核心利器之一,但是我们或多或少都会遇到required a single bean, but 2 were found(2可能是其他数字)的问题,接下来我们从源码的角度去看为什么会出现这个问题,以及这个问题的解法是什么? 首先我们写一个demo来复现一下这个问题.首先我们有一个抽象类AbstractAutowiredDemo,两个实现类AutowiredDemo1,AutowiredDemo2.然后我们在AutowiredDemoContr…
Parameter 0 of method orderSqlSessionFactory in com.config.MultipleDBConfig required a single bean, but 2 were found: - orderDataSource: defined by method 'orderDataSource' in class path resource [com/config/MultipleDBConfig.class] - crmDataSource: d…
技术群: 816227112 参考:https://stackoverflow.com/questions/43455869/could-not-autowire-there-is-more-than-one-bean-of-datasource-type Parameter 0 of method redisTemplate in org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration required…
原因: @EnableAutoConfiguration 这个注解会把配置文件号中的数据源全部都自动注入,不会默认注入一个,当使用其他数据源时再调用另外的数据源. 解决方法: 1.注释掉这个注解 2.通过如下的方式禁止springboot自动注入多个数据源 @SpringBootApplication( exclude ={ DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class…
TClientDataSet 提交时提示 Field value Required 但是未提示具体哪个字段. 这个错误特别麻烦,要使用 midas 控件时,虽然很方便.但是出错了根本找不到原因,特别是这个异常.下面的补丁,可以帮助找到错误原因. 注:我们自己在使用的时候,采用了控件继承,因此可以把这个功能变成控件基本功能,但是继承相关代码特别多,就不在这里贴了. procedure postAndCheckValue(ds: TDataSet); var I: Integer; curField…
1.完整报错 *************************** APPLICATION FAILED TO START *************************** Description: Field relTelBillRecordRepository in com.xx.service.TelParseService required a bean of type 'com.xx.repository.IRelTelBillRecordRepository' that co…
错误截图 后面发现原来和入口类代码有关. //@SpringBootApplication(scanBasePackages = {"org.jzc.odata.cboard","org.jzc.odata.cboard.odataservice","com.sdl.odata.api.service","com.sdl.odata.api.service.ODataService"}) @EnableAutoConfigur…
一.引言 在开发中经常会碰到这样的情形,一个接口会有不同的实现,但在开发中都是基于接口的注入,那么怎么根据不同的需求注入不同的类型就是一个值得考虑的问题.在注入属性时常用的两个注解是@Autowired和@Resource,使用它们便可以实现,同时spring提供了很多@ConditionalXXX的注解,可以很好的完成上述功能: 二.代码演示 1.问题代码描述 使用代码的方式描述下上面提到的问题,后面给出解决方案. controller类,TestConditionalOnProperty.j…
架构体系 在谈spring bean的重新加载前,首先我们来看看spring ioc容器. spring ioc容器主要功能是完成对bean的创建.依赖注入和管理等功能,而这些功能的实现是有下面几个组件完成的: Resource:对资源的抽象,不同的资源有不同的实现,例如:ClasspathResource.FileSystemResource... BeanDefinition:描述一个具体的bean,里面包含了bean的一些基本信息,不同类型的bean也有不同的实现类:ScannedGene…
首先来看一段代码,看过上一节的朋友肯定对这段代码并不陌生.这一段代码诠释了Spring加载bean的完整过程,包括读取配置文件,扫描包,加载类,实例化bean,注入bean属性依赖. <span style="font-size:18px;">public void refresh() throws BeansException, IllegalStateException { synchronized (this.startupShutdownMonitor) { //…
首先来看一段代码,看过上一节的朋友肯定对这段代码并不陌生.这一段代码诠释了Spring加载bean的完整过程,包括读取配置文件,扫描包,加载类,实例化bean,注入bean属性依赖. public void refresh() throws BeansException, IllegalStateException { synchronized (this.startupShutdownMonitor) { // Prepare this context for refreshing. prep…
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. 2017-05-13 20:11:30.651 ERROR 1869 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION…
引言 前文我们介绍了关于如何学习Spring的源码以及解析了spring中加载配置文件注册Beandefinition的过程.今天我们继续学习DI的过程. 创建实例和DI过程 IOC和DI都是对spring容器特性的描述.IOC指的是将实例的生命周期交给第三方管理(spring).而DI的侧重点在于某一个类依赖了其他的实例,将实例注入到依赖它的实例的过程.所以可以很明显的看出来DI是发生在类实例已经实例化完成之后的. 创建实例 BeanDefinition BeanDefinition是对bea…
标题中的咖啡罐指的是Spring容器,容器里装的当然就是被称作Bean的豆子.本文我们会以一个最基本的例子来熟悉Spring的容器管理和扩展点. 阅读PDF版本 为什么要让容器来管理对象? 首先我们来聊聊这个问题,为什么我们要用Spring来管理对象(的生命周期和对象之间的关系)而不是自己new一个对象呢?大家可能会回答是方便,为了解耦.我个人觉得除了这两个原因之外,还有就是给予了我们更多可能性.如果我们以容器为依托来管理所有的框架.业务对象,那么不仅仅我们可以无侵入调整对象的关系,还有可能无侵…
Field userService in com.demo.web.Controller.HomeController required a single bean, but 2 were found:    - userServiceImpl: defined in file [C:\Users\xxxx\Desktop\r\maven-projects\web-app\target\classes\com\demo\web\Controller\UserServiceImpl.class] …
Spring框架主要包括IoC和AOP,这两大功能都可以使用注解进行配置. 开发环境:IntelliJ IDEA 2019.2.2Spring Boot版本:2.1.8新建一个名称为demo的Spring Boot项目. 一.bean定义 在 Spring 中,构成应用程序主干并由Spring IoC容器管理的对象称为bean.bean是一个由Spring IoC容器实例化.组装和管理的对象.使用@Component.@Service或@Configuration注解来修饰一个类,这些类会被Sp…
概述 第一次用maven工具打war包,出现各种各样的问题,做个问题记录方便下次查看 maven 一开始用的maven是springboot默认的,在.m2下,要打包时才发现没有mvn指令.索性自己就重新装个maven,去官网下载,我安装的是3.5.2版本.因为maven仓库默认是国外的,需要更改为国内的镜像地址,方便建立本地的仓库,于是更改setting.xml文件,在<mirrors>标签内添加一个新的标签,完成之后自己配置环境变量,下图是lz自己电脑的配置,根据自己安装目录进行,完成后测…
话不多说直接上代码: 声明一个接口userDao: package ioc.hello; public interface UserDao { public void test(); } 2个实现类: package ioc.hello; import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Component; @Component("userdao")…
文章要点 Spring bean 的声明方式 Spring bean 的注入规则 Spring bean 的依赖查找规则 Spring bean 的名称定义方式和默认名称规则 XXX required a bean of type 'XXX' that could not be found. 这种情况,一般是因为没有在 Spring bean 容器中找到对应的 bean . bean 的声明 使用一个 bean,首先要声明一个 bean,使之交给 Spring 管理 声明一个 bean , 常用…
今天接下去讲我们的内容,上次的解析了AnnotationBeanUtils这个类的运用和源码.今天主要关注的是Autowired和 AutowiredAnnotationBeanPostProcessor这2个类.首先我们来看一下Autowired标签的定义. @Target({ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD, ElementType.ANNOTATION_…
在AuthorizationServerConfigurerAdapter,重写一个TokenServices,注意这里的@Primary 非常重要,否则会有3个同类型的Bean,无法注入,会抛出以下异常 org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.springframework.security.oauth2.provider.token.R…
目录 Spring Boot 上传文件 功能实现 增加ControllerFileUploadController 增加ServiceStorageService 增加一个Thymeleaf页面 修改一些简单的配置application.properties 修改Spring Boot Application类 官网没有说明其他的Service类的定义 至此,运行项目.可以再上传与下载文件 介绍@ConfigurationProperties的用法 上面例子的 @ConfigurationPro…
Spring 依赖注入优化 原创: carl.zhao SpringForAll社区 今天 Spring 最大的好处就是依赖注入,关于什么是依赖注入,在Stack Overflow上面有一个问题,如何向一个5岁的小孩解释依赖注入,其中得分最高的一个答案是: When you go and get things out of the refrigerator for yourself, you can cause problems. You might leave the door open, y…
2018-12-06 16:58:35,709 [ main ] - [ INFO ] [ org.springframework.core.KotlinDetector : 57 ] - Kotlin reflection implementation not found at runtime, related features won't be available. . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\__…
这一讲分析spring bean属性注入代码populateBean,源码分析如下 /** * Populate the bean instance in the given BeanWrapper with the property values * from the bean definition. * 丰富bean实例属性 * @param beanName the name of the bean * @param mbd the bean definition for the bean…
SSO介绍 什么是SSO 百科:SSO英文全称Single Sign On,单点登录.SSO是在多个应用系统中,用户只需要登录一次就可以访问所有相互信任的应用系统.它包括可以将这次主要的登录映射到其他应用中用于同一个用户的登录的机制.它是目前比较流行的企业业务整合的解决方案之一. 简单来说,SSO出现的目的在于解决同一产品体系中,多应用共享用户session的需求.SSO通过将用户登录信息映射到浏览器cookie中,解决其它应用免登获取用户session的问题. 为什么需要SSO 开放平台业务本…