admin管理员组

文章数量:1530518

一、抛出异常

Parameter 0 of constructor in com.ylz.supervise.childmodule.sys.log.strategy.StrategyContext required a single bean, but 2 were found:
	- logBpService: defined in file [H:\item\radiate\radiate-supervise\target\classes\com\ylz\supervise\childmodule\sys\log\service\LogBpService.class]
	- logHsService: defined in file [H:\item\radiate\radiate-supervise\target\classes\com\ylz\supervise\childmodule\sys\log\service\LogHsService.class]


Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

二、产生场景

由于业务功能需求需要日志记录操作信息,为此建立了一个日志策略类方便多模块记录。结果当加入了第二个模块时就出现异常。项目无法启动,启动则抛出上述异常。

三、部分代码

  1. 日志策略类
    package com.ylz.supervise.childmodule.sys.log.strategy;
    
    import org.springframework.context.annotation.Primary;
    import org.springframework.stereotype.Service;
    
    /**
     * @ClassName: 日志策略
     * @author: Created by CCJ on 2020/5/7.
     **/
    @Service
    public interface LogStrategy {
        /**
         * 日志保存方法
         */
        void saveLog(Object... args) throws Exception;
    }
    

     

  2.  实现类

    package com.ylz.supervise.childmodule.sys.log.strategy;
    
    
    import com.ylz.supervise.childmodule.sysm.CommService;
    
    /**
     * 策略类
     */
    @CommService
    public class StrategyContext {
    
        private LogStrategy strategy;
    
        public StrategyContext(LogStrategy strategy) {
            this.strategy = strategy;
        }
    
        public void executeStrategy(Object... args) throws Exception {
            strategy.saveLog(args);
        }
    }

     

 

四、产生问题原因

 产生问题的原因是由于实现类注解@CommService的使用。具体原因暂时还不清楚,暂时解决是直接把注解去掉,不自动注入。因为项目内调用部分目前也是使用new的方式,所以影响不大。不过还是没搞明白具体原因,因为初步使用策略类还未了解多少。待日后学成时再回头看。嘿嘿,Σσ(・Д・;)我我我什么都没做!!!

本文标签: 异常ylzsuperviseconstructorchildmodule