我在其他类注入的时候出现以下错误

@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\com\xxx\xxx\service\impl\MibServiceImpl.class]
- nodeAgentServiceImpl: defined in file [F:\xxxx\monitorcenter\target\classes\com\xxx\xxx\service\impl\NodeAgentServiceImpl.class]

解决方法:在mibService实现类添加注解

@Primary

springboot环境下遇到这个问题,解决方案参考来源:https://stackoverflow.com/questions/46343560/class-required-a-single-bean-but-2-were-found

public interface OIDService {
} @Slf4j
@Service
public class OIDServiceImpl implements OIDService {
} public interface MibService extends OIDService{
} @Service
@Slf4j
@Primary
public class MibServiceImpl extends OIDServiceImpl implements MibService
{} public interface NodeAgentService extends MibService{
} @Service
@Slf4j
public class NodeAgentServiceImpl extends MibServiceImpl implements NodeAgentService {
}

Field in required a single bean, but 2 were found:的更多相关文章

  1. Field amqpTemplate in * required a single bean, but 3 were found:

    Field amqpTemplate in * required a single bean, but 3 were found: Spring Boot 启动的时候报的错 使用Spring Boot ...

  2. 【记录】Field required a single bean, but 2 were found:

    重构遇到个小问题,记录下: 错误信息: *************************** APPLICATION FAILED TO START ************************ ...

  3. Field baseMapper in com.baomidou.mybatisplus.extension.service.impl.ServiceImpl required a single bean, but xx were found:

    在学习使用 mybatis-plus 时,遇到一个奇怪的异常 如 代码一: 代码一: Error starting ApplicationContext. To display the conditi ...

  4. @Autowired注解 --required a single bean, but 2 were found出现的原因以及解决方法

    @Autowired注解是spring用来支持依赖注入的核心利器之一,但是我们或多或少都会遇到required a single bean, but 2 were found(2可能是其他数字)的问题 ...

  5. Parameter 0 of method sqlSessionTemplate in org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration required a single bean, but 2 were found:

    Parameter 0 of method orderSqlSessionFactory in com.config.MultipleDBConfig required a single bean, ...

  6. springboot多数据源启动报错:required a single bean, but 6 were found:

    技术群: 816227112 参考:https://stackoverflow.com/questions/43455869/could-not-autowire-there-is-more-than ...

  7. Spring多个数据源问题:DataSourceAutoConfiguration required a single bean, but * were found

    原因: @EnableAutoConfiguration 这个注解会把配置文件号中的数据源全部都自动注入,不会默认注入一个,当使用其他数据源时再调用另外的数据源. 解决方法: 1.注释掉这个注解 2. ...

  8. TClientDataSet 提交时提示 Field value Required 但是未提示具体哪个字段。

    TClientDataSet 提交时提示 Field value Required 但是未提示具体哪个字段. 这个错误特别麻烦,要使用 midas 控件时,虽然很方便.但是出错了根本找不到原因,特别是 ...

  9. springboot jpa mongodb 整合mysql Field in required a bean of type that could not be found Failed to load ApplicationContext

    1.完整报错 *************************** APPLICATION FAILED TO START *************************** Descripti ...

随机推荐

  1. linux获取某一个网卡的ipv4地址

    ip a show ens33 | grep inet | grep -v inet6 | awk '{print $2}' | awk -F '/' '{print $1}'

  2. Arduino短学期作业展示

    自己挖的坑终于填上了,真是欣慰啊= = 源代码:https://github.com/Miyeah/Arduino-Dormitory-Assistant Arduino-Dormitory-Assi ...

  3. Java语言基础(7)

    1 for循环 案例:Demo1 1+1/2+1/3+1/4+1/5+1/6+...+1/100 = ? 1/1+1/2+1/3+1/4+1/5+1/6+...+1/100 = ? 分子都是1,分母是 ...

  4. zencart分类页每页显示产品数量自定义选择的方法

    zencart默认分类页每页显示产品数量是固定的,如何让顾客可以选择每页显示的产品的数量呢?效果图 方式一:全部展示 方式二:下拉菜单 修改方法 1.导入sql INSERT INTO configu ...

  5. main方法类 为何由AppClassLoader加载

    AppClassLoader AppClassLoader应用类加载器,又称系统类加载器,负责在JVM启动时加载来自命令java中的classpath或者java.class.path系统属性或者CL ...

  6. TXNLP 09-17

    上节课讲了一些算法的复杂度,都比较简单,我就没有单独截图.1 n n^2 nlogn logn...等等 其实一些排序问题也比较简单.还是给大家列举一下. 归并排序: 主定理定理..吐血 算法复杂度相 ...

  7. 07 saltstack生产实例-mysql主从

    1.服务部署 .服务部署 抽象:功能模块 redis 安装.配置.启动 mysql 安装.配置(my.cnf可以统一 目录默认配置可以统一) master: server_id slave: serv ...

  8. [Functional Programming] Examples: When and Unless

    /** * When */ const _branch = (x) => { const result = (x && x.isPublic) ? dissoc('private ...

  9. SQL Server 删除日志文件

    -- 查询日志文件名,用于下面删除 USE [data_name] GO SELECT file_id, name FROM sys.database_files /*删除指定数据库的日志文件*/ U ...

  10. hdu 6070 Dirt Ratio

    题 OvO http://acm.hdu.edu.cn/showproblem.php?pid=6070 (2017 Multi-University Training Contest - Team ...