zoukankan      html  css  js  c++  java
  • @Qualifier 注解指定装备特定的bean

    public interface TestService {
        String test();
    }
    
    
    @Service("aTestService")
    public class ATestServiceImpl implements TestService{
    
        @Override
        public String test() {
            return "A";
        }
    }
    
    
    @Service("bTestService")
    public class BTestServiceImpl implements TestService {
    
        @Override
        public String test() {
            return "B";
        }
    }

    测试

    @RestController
    @RequestMapping("/test")
    public class TestController {
    
        @Autowired
        TestServiceImpl testServiceImpl;
    
        @RequestMapping("/a")// localhost:8080//test/a?type=0
        public String test(int type){
            return testServiceImpl.test(type);
        }
    }
    @Service
    public class TestServiceImpl {
    
        @Autowired
        @Qualifier("aTestService")
        TestService aTestService;
    
        @Autowired
        @Qualifier("bTestService")
        TestService bTestService;
    
        public String  test(int type){
            if (0==type) {
                return aTestService.test();
            }else{
                return bTestService.test();
            }
        }
    }

    结果:

    http://localhost:8080//test/a?type=0   结果为A
    
    http://localhost:8080//test/a?type=1   结果为B
  • 相关阅读:
    微信公众号支付JSAPI,提示:2支付缺少参数:appId
    Application对象
    Apache安装和文件配置
    Apache编译教程
    MS4W安装教程
    MapServer教程2
    Tomcat修改源码,重新编译
    MapServer教程
    QGIS SDK下载
    OpenStreetMap全球库
  • 原文地址:https://www.cnblogs.com/yrjns/p/13559429.html
Copyright © 2011-2022 走看看