美文网首页
Choerodon Spring Boot 1.5.x迁移2.0

Choerodon Spring Boot 1.5.x迁移2.0

作者: superlee01 | 来源:发表于2019-03-27 17:16 被阅读0次

官方指南

spring boot 2.0 升级指南

Spring Boot Security 2.0升级指南

pom文件修改

  • choerodon-framework-parent升级为0.9.0.RELEASE
  • choerodon.starters.version升级为0.10.0.RELEASE
  • spring-cloud-starter-eureka => spring-cloud-starter-netflix-eureka-client
  • spring-cloud-starter-zuul => spring-cloud-starter-netflix-zuul
  • spring-cloud-starter-feign => spring-cloud-starter-openfeign
  • spring-cloud-starter-eureka-server => spring-cloud-starter-netflix-eureka-server

单元测试

单元测试报如下:

java.lang.IllegalStateException: Failed to transform class with name io.choerodon.iam.app.service.impl.AccessTokenServiceImplSpec. Reason: null
...
Caused by: java.util.ConcurrentModificationException
...

或者

java.lang.IllegalStateException: Failed to load ApplicationContext
...
Caused by: java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker
...
Caused by: java.lang.NoClassDefFoundError: org/mockito/cglib/proxy/MethodInterceptor
...
Caused by: java.lang.ClassNotFoundException: org.mockito.cglib.proxy.MethodInterceptor
解决方法:
  • powermock.version 1.7.4 => 2.0.0-beta.5
  • powermock-api-mockito => powermock-api-mockito2
  • 添加指定版本javassist
        <dependency>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.24.0-GA</version>
        </dependency>

如果单元测试里有自己mock的DiscoveryClient,需要在application-test.yml文件中将Spring boot 2.0自动注入的几个DiscoveryClient排除掉,否则会报primary bean冲突的问题

spring:
  autoconfigure:
    exclude:
      - org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration
      - org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration
      - org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration
      - org.springframework.cloud.client.discovery.composite.CompositeDiscoveryClientAutoConfiguration
      - org.springframework.cloud.client.discovery.noop.NoopDiscoveryClientAutoConfiguration

配置修改

  • spring.http.multipart => spring.servlet.multipart
  • management.port => management.server.port
  • 许多server.*属性 ( Servlet 特有的) 已经转移到server.servlet.*, 比如server.context-path --> server.servlet.context-path
  • security.ignored被移除,使用代码替代@Value("${security.ignored:/choerodon/**")
  • management.security.*去除,默认只有端点/health/info是暴露的,开放所有端点可以使用management.endpoints.web.exposure.include=*
  • endpoints.<id>.enabled修改为management.endpoint.<id>.enabled

chart修改

  • 修改deployment.yamlreadinessProbe探针,localhost:{{ .Values.deployment.managementPort }}/health => localhost:{{ .Values.deployment.managementPort }}/actuator/health
  • 修改values.yaml中的metrics.path /prometheus=>/actuator/prometheus

导入包

  • org.springframework.cloud.netflix.feign => org.springframework.cloud.openfeign
  • org.springframework.boot.bind不再可用,并被新的宽松绑定规则所取代, RelaxedDataBinderBinder取代

相关文章

网友评论

      本文标题:Choerodon Spring Boot 1.5.x迁移2.0

      本文链接:https://www.haomeiwen.com/subject/puszvqtx.html