springcloud1 升级到springcloud2所遇到的坑总结

目前项目的架构没有采用任何网关、采用nginx直连方式,因现在考虑加入软网关、并且采用spring cloud gateway的支持、至此升级到2.0版本、在升级期间遇到了一些问题、看了不少官方文档、将目前所遇到的问题汇总如下。

1:升级spring cloud2 先更改相应的maven相关的配置可参照:

https://blog.csdn.net/qq_36752632/article/details/79497130 

注:如果你使用logback需保证logstash.logback.encoder版本在5.1以上。

2:使用工具检查对应的jar包版本有没有相应冲突如果发现出现冲突。请按照spring提供的包版本为准

3: spring cloud config中如果采用的本地存储方式,并且你在1*中根据label进行区分、请注意。

在2中请把

spring.cloud.config.label=global-config

改为

spring.cloud.config.label=/global-config

官网上介绍说明。添加的label会放入后面进行拼接地址。所以需要加入斜杠标识

4:如果使用有security安全规则并且是通过配置文件如properties配置的请更换成Bean方式进行配置。2*不在支持该方式1*上的安全配置是

security.basic.enabled=true

security.basic.path=/monitor

security.user.name=mhuang

security.user.password=huangmiao

management.security.roles=SUPERUSER

management.context-path=/monitor

management.security.enabled=true

endpoints.metrics.sensitive=false

endpoints.metrics.enabled=true

endpoints.health.sensitive=false

endpoints.health.enabled=true

在2*上官方已经屏蔽了这种方式。过时掉、官方提供的说明是需要采用自己配置Bean的方式进行配置。下方上配置代码

properties中

management.endpoints.web.exposure.include=*management.endpoints.web.base-path=/monitorspring.security.user.name=你的账号spring.security.user.password=你的密码spring.cloud.bus.trace.enabled=true

@Configuration

@EnableWebSecurity

public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired

    private Environment env;

    @Override

    protected void configure(HttpSecurity http) throws Exception {

        http.authorizeRequests().antMatchers("需要校验的url").hasRole("ADMIN")

                .anyRequest().permitAll().and()

                .formLogin().loginPage(env.getProperty("security.loginUrl","/login")).permitAll().and()

                .logout().permitAll();

    }

}

5:在特定版本中使用有DB、请更换相应的springboot包。低版本有可能会出现循环注册Bean的问题。新版springboot2.0.4修复了这个问题、如果不想升级请按照官方条件关闭SpringCloud刷新策略

5.1 方案修改作者提供的解决方式org.springframework.bootspring-boot-starter-parent2.0.4.RELEASEspring cloud 升级到org.springframework.cloudspring-cloud-dependenciesFinchley.SR1pomimport具体改动的源码可以在spring-beans 包下 AbstractBeanFactory类中的doGetBean方法

if (mbd.isSingleton()) {

  sharedInstance = getSingleton(beanName, () -> { //此处在5.0.8之前出现循环Bean的时候会在创建bean对象抛出异常,有兴趣可以对比看下历史和新版的这个里面的区别

      try {

        return createBean(beanName, mbd, args);

      }

      catch (BeansException ex) {

        // Explicitly remove instance from singleton cache: It might have been put there

        // eagerly by the creation process, to allow for circular reference resolution.

        // Also remove any beans that received a temporary reference to the bean.

        destroySingleton(beanName);

        throw ex;

      }

  });

  bean = getObjectForBeanInstance(sharedInstance, name, beanName, mbd);

}

5.2 方案添加 spring.cloud.refresh.refreshable=none(使用这个配置请记住则不能通过命令进行刷新相关配置)

6:如果你当前模块使用有spring-data-redis、并且你在代码中实现了切库、请注意、2*默认已经切换成了lettuce redis客户端代理jedis成为默认的client、默认的lettuce是本地安全的链接、不允许使用垮库方式、请根据源码相应位置修改RedisTeamplate中的相关属性或者重构lettuceFactory相关工厂类定义ShareNative为false即可。就可支持垮库查询,如果量不大还可直接通过或者方式进行实现如果你采用spring-boot中的redis或者spring-data-redis 2*的话、默认现在使用lettuce client方式、需要通过下面代码进行设置、

感谢天涯的助攻地址: https://blog.csdn.net/zhongzunfa/article/details/81367355

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值