zoukankan      html  css  js  c++  java
  • 解除项目与其他服务的强依赖

    项目中使用了其他项目中的服务,当服务不可用或者报错的时候,项目启动不了,需要解除强依赖

    例如之前的写法:

    @Configuration
    public class EpasBeanConfig {
    
    @Bean
    public GroupOrganizationService getGroupOrganizationService(){
        return EpasClientFactory.createClient(GroupOrganizationService.class,Constants.EPAS_USER_BASIS_APP_KEY);
    }
    
    @Bean
    public DepartmentService getDepartmentService(){
        return EpasClientFactory.createClient(DepartmentService.class, Constants.EPAS_USER_BASIS_APP_KEY);
    }
    }
    @Autowired
    private GroupOrganizationService groupOrganizationService;
    
    @Autowired
    private DepartmentService departmentService;

    当服务不可用的时候,项目启动失败

    修改后的方法:

    @Configuration
    public class EpasBeanConfig {
    
        @Bean
        @Lazy
        public GroupOrganizationService getGroupOrganizationService(){
            return EpasClientFactory.createClient(GroupOrganizationService.class, Constants.EPAS_USER_BASIS_APP_KEY);
        }
        
        @Bean
        @Lazy
        public DepartmentService getDepartmentService(){
            return EpasClientFactory.createClient(DepartmentService.class, Constants.EPAS_USER_BASIS_APP_KEY);
        }
    }
    GroupOrganizationService groupOrganizationService = AppContextHolder.getContext().getBean(GroupOrganizationService.class);
  • 相关阅读:
    jQuery操作单选按钮(Radio)
    Django:DRF实现模糊搜索
    Django:实现导入功能,及下载模版
    python使用DES加密解密
    在线OCR识别
    bootstrap-table导出时存在bootstrap-switch按钮如何导出
    Django:解决时间显示格式含有T
    翻页时bootstrap-switch样式失效
    bootstraptable导出
    统计文件行数
  • 原文地址:https://www.cnblogs.com/zhouj850/p/10864197.html
Copyright © 2011-2022 走看看