zoukankan      html  css  js  c++  java
  • SpringBoot中实现Spring容器中注入类型相同但名不同Bean

        @Bean(autowire = Autowire.BY_NAME,value = "kaptchaProducer")
        public Producer kaptchaProducer() {
            Properties kaptchaProperties = new Properties();
            kaptchaProperties.put("kaptcha.border", "no");
            kaptchaProperties.put("kaptcha.textproducer.char.length","4");
            kaptchaProperties.put("kaptcha.image.height","50");
            kaptchaProperties.put("kaptcha.image.width","150");
            kaptchaProperties.put("kaptcha.obscurificator.impl","com.google.code.kaptcha.impl.ShadowGimpy");
            kaptchaProperties.put("kaptcha.textproducer.font.color","black");
            kaptchaProperties.put("kaptcha.textproducer.font.size","40");
            kaptchaProperties.put("kaptcha.noise.impl","com.google.code.kaptcha.impl.NoNoise");
            //kaptchaProperties.put("kaptcha.noise.impl","com.google.code.kaptcha.impl.DefaultNoise");
            kaptchaProperties.put("kaptcha.textproducer.char.string","acdefhkmnprtwxy2345678");
    
            Config config = new Config(kaptchaProperties);
            return config.getProducerImpl();
        }
    
        @Bean(autowire = Autowire.BY_NAME,value = "kaptchaProducerH5")
        public Producer kaptchaProducerH5() {
            Properties kaptchaProperties = new Properties();
            kaptchaProperties.put("kaptcha.border", "no");
            kaptchaProperties.put("kaptcha.textproducer.char.length","4");
            kaptchaProperties.put("kaptcha.image.height","50");
            kaptchaProperties.put("kaptcha.image.width","150");
            kaptchaProperties.put("kaptcha.obscurificator.impl","com.google.code.kaptcha.impl.ShadowGimpy");
            kaptchaProperties.put("kaptcha.textproducer.font.color","black");
            kaptchaProperties.put("kaptcha.textproducer.font.size","40");
            kaptchaProperties.put("kaptcha.noise.impl","com.google.code.kaptcha.impl.NoNoise");
            //kaptchaProperties.put("kaptcha.noise.impl","com.google.code.kaptcha.impl.DefaultNoise");
            kaptchaProperties.put("kaptcha.textproducer.char.string","0123456789");
    
            Config config = new Config(kaptchaProperties);
            return config.getProducerImpl();
        }
    

      

        @Resource(name = "kaptchaProducer")
        private Producer kaptchaProducer;
    
        @Resource(name = "kaptchaProducerH5")
        private Producer kaptchaProducerH5;
    

      

  • 相关阅读:
    Java规约之方法设计
    JVM第一篇 JVM与Java体系结构
    初学者学习Java方法集
    初学者学习Java方法集
    1.Spring-Boot 静态文件和页默认放置位置
    2.Spring-Boot常用配置解释
    3.Spring-Boot核心@SpringBootApplication介绍
    4.Spring-Boot中基于Junit的单元测试
    vue学习笔记(一) ---- vue指令(v-for 和 key 属性)
    vue学习笔记(一) ----- vue指令(菜单列表案例)
  • 原文地址:https://www.cnblogs.com/jtlgb/p/11796716.html
Copyright © 2011-2022 走看看