最近在Spring的注解中,尝试获取一个Bean出现了如题所示的错误。
NoUniqueBeanDefinitionException: No qualifying bean of type is defined: expected single matching bean but found 2:sysRoleManage, sysRoleManageImpl
我有2个类,1个是接口:
public interface SysRoleManager{ //............ }
另一个是该接口的实现类:
@Compnent public class SysRoleManagerImpl implements SysRoleManager{ //............实现抽象方法 }
尝试获取bean的时候:
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(ServletContext); SysRoleManager manager = ctx.getBean(SysRoleManager.class); System.out.println(manager);
得到如题所示的错误。
解决办法,在实现类上的注解要更详细些,改成:
@Service("sysRoleManager") public class SysRoleManagerImpl implements SysRoleManager{ //............实现抽象方法 }
这样,就能解决问题,打印出:
com.xx.xxx.SysRoleManagerImpl@179e64
说明获取到了实现类。
或者可以不用通过Spring上下文去获取,直接透过注解的方式:
@Autowire @Qualifier("sysRoleManager ") private SysRoleManager manager;
假如有多个实现类实现同一接口,需要在每个实现类上注解不同的@Service("name"),name为不同值。
顺便补充下hibernate的一个异常:例如,
org.hibernate.HibernateException: identifier of an instance
of org.cometd.hibernate.User altered from 12 to null。
那是因为:
1)你是否在注解的时候把非主键的字段配置了@NaturalId等主键生成策略;
2)是否在一个事务中更新了主键,而主键是不能被更新的。
相关推荐
【文件夹】名称: log文件名称: business-provider_debug.log文件名称: business-provider_error.log 主要可以看下这个日志,主要是事务找不到管理器文件... expected single matching bean but found 2: dataSourceTr
"Taotao商城数据库.zip" 是一个包含了与Java相关的数据库脚本文件的压缩包,主要用于在MySQL客户端工具中创建和管理Taotao电商平台的数据库。这个压缩包可能包含了一系列SQL语句,用于创建表结构、定义数据关系以及...
org.springframework.transaction-3.2.4.RELEASE.jar,最新版的org.springframework.transaction,Wed Aug 07 16:44:37 GMT+01:00 2013
部署了一套非常全的OAuth2.0的例子 其中包括客户端和服务器端,专门为了OAuth2.0初学者提供了一个学习的资料 可以参考微博地址:http://blog.csdn.net/jbjwpzyl3611421/article/details/51130030
在使用JDBC作为数据访问技术的时候,Spring Boot为我们定义了PlatformTransactionManager的实现DataSourceTransactionManager的Bean。在使用JPA作为数据访问技术的时候,Spring Boot为我们定义了...
2-传输端口:9300(二进制 api) 官方 java 客户端连接到端口 9300 API-1 : Method :GET GET : Response : [ { "productName": "Orange", "descripation": "有益健康提高免疫力", "category": "agriculture", "tag":...
After the nonclustered key at the leaf level of the index is found, only one more page access is needed to find the data row. Searching for a single row using a nonclustered index is almost as ...
We can declare (but not define) functions with arguments, and/or return values, of type Foo. (One exception is if an argument Foo or const Foo& has a non-explicit, one-argument constructor, in which ...
Another type of table lock is a schema stability lock (Sch-S) and is compatible with all table locks except the schema modification lock (Sch-M). The schema modification lock (Sch-M) is incompatible ...
A participating team's algorithm must predict grades on the entire qualifying set, but they are only informed of the score for half of the data, the quiz set of 1,408,342 ratings. The other half is ...
like this is no longer accepted: { . . . jump_label: } If you have code like this, change it to look like this: { . . . jump_label: ; /* need a statement here! */ } o TCC has a ...
in mathematics, it is beautiful and compelling, and there is a plethora of material. The literature in complex variables is vast and diverse. There are a great many textbooks in the subject, but each ...
About the INFORMS Certified Analytics Professional (CAP®) Program INFORMS is pleased to continue the implementation of CAP® the professional certification program that meets the needs of analytics ...
Guidelines for qualifying PV modules, components and materials for operation at high temperatures PD IEC TS 63126:2020 是一份关于太阳能photovoltaic (PV) 模块、组件和材料在高温条件下的合格指南。该标准...
- `qualifying($type = null)`:用于广告查询,可以获取竞价排位和竞价状态。 - `listAD($num = null)`:提供广告状态列表,可选择显示指定数量的广告。 - `outADInfo($num)`:输出所有有效的广告信息。 - `...
完整英文版 IEC TS 63126:2020 Guidelines for qualifying PV modules, components and materials for operation at high temperatures(光伏组件、组件和材料在高温下运行的资格指南)。 IEC TS 63126:2020 定义...
在您的终端中,运行cd phillies-qualifying-offer 运行npm install 要以development模式运行应用程序,请运行npx next dev 要以production模式运行应用程序, npx next build运行npx next build ,然后再运行npx ...
Table of Contents Copyright Brief Table of Contents Table of Contents Praise for the Third Edition of Spring in Action Preface Acknowledgments About this Book 1. Core Spring Chapter 1. Springing into ...