zoukankan      html  css  js  c++  java
  • spring注入map,spring注入一个接口的多个实现类在map里

    spring注入map,spring注入多个实现类在map里

    一个接口,两个实现类

    接口:

    public interface TestService {
        void test();
    }

    两个实现类

    @Component("testOService")
    public class TestOService implements TestService {
        @Override
        public void test() {
            System.out.println("testOService");
        }
    }
    @Component("testTwoService")
    public class TestTwoService implements TestService {
        @Override
        public void test() {
            System.out.println("testTwoService");
        }
    }

    查看:

    @Service
    public class UserInfoService {
        
        @Autowired
        private Map<String ,TestService> testServiceMap;
        @PostConstruct
        public void init(){
            testServiceMap.get("testOService").test();
            testServiceMap.get("testTwoService").test();
        }
    }

    源码解析

    对应spring源码位置 org.springframework.beans.factory.support.DefaultListableBeanFactory

    方法 : org.springframework.beans.factory.support.DefaultListableBeanFactory#resolveMultipleBeans

  • 相关阅读:
    自定义样式滚动条
    html文本超出加省略号
    getcomputedstyle和style的区别
    模块化设计
    js数组取出非重复元素
    vue 获取元素高度
    js 滚动条滑动
    swiper基本使用
    flex弹性盒子布局
    js 地区三级联动 2
  • 原文地址:https://www.cnblogs.com/liran123/p/13039283.html
Copyright © 2011-2022 走看看