Spring Boot 2.0 Upgrade Notes

1. Background

The original Spring Bootversion of the project is 1.5.4.RELEASE, Spring Cloudversion is Dalston.SR2, and the upgraded Spring Bootversion is 2.0.0.M7, Spring Cloudversion is Finchley.M5, the API and dependency packages of each component have changed due to the version upgrade. The following is the upgrade method of the components used in the project.

2. Spring Security

The project uses the Oauth2protocol specification, and the authenticated Tokentoken is used Redisfor storage.

2.1 Authorization server

  • The password configured by the client is changed from the original plaintext to ciphertext.
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.inMemory()
                .withClient("android")
                .scopes("xx")
                .secret("$2a$10$sCeoatJoccD4y1ff8AhdROLd2u6AWYBwH7YrbWXxdk6fA4VGhGITm") // 原先的代码:.secret("android")
                .authorizedGrantTypes("password", "authorization_code", "refresh_token");
    }
}

2.2 Resource server (resource server)

  • Spring Boot 2.0.0.M7The automatic configuration autoconfigurein the reference ResourceServerhas been removed and will be moved to the Spring Securityproject. The current alternative is to use https://github.com/spring-projects/spring-security-oauth2-boot.git, add the following dependencies:
  <dependency>
    <groupId>org.springframework.security.oauth.boot</groupId>
    <artifactId>spring-security-oauth2-autoconfigure</artifactId>
    <version>2.0.0.BUILD-SNAPSHOT</version>
  </dependency>

2.3 RewriteRedisTokenStore

  • For RedisTokenStorethe NoSuchMethodError RedisConnection.set([B[B)Verror that occurs, the current solution is to rewrite RedisTokenStoreline 160 and conn.set(accessKey, serializedAccessToken);modify it toconn.stringCommands().set(accessKey, serializedAccessToken);

3. ElasticSearch

Since the project is deployed on Alibaba Cloud, and Alibaba Cloud recommends using REST APIand ElasticSearchinteracting with it, the project was Spring Data Elasticsearchswitched from the original to Spring Data Jestthe ElasticSearchclient.

  • rely
<dependency>
    <groupId>com.github.vanroy</groupId>
    <artifactId>spring-boot-starter-data-jest</artifactId>
    <version>3.0.0.RELEASE</version>
</dependency>
<dependency>
    <groupId>io.searchbox</groupId>
    <artifactId>jest</artifactId>
    <version>5.3.2</version>
</dependency>
  • Connection configuration
spring:
  data:
    jest:
      uri: http://192.168.1.222:9200
      username: elastic
      password: changeme

4. Spring Cloud Feign

The project is used Feignas a Restclient for remote calls. After the Spring Cloudversion is upgraded, the Feigndependencies are changed to:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

5. log4j

Spring Boot 2.0.0.M7The dependency has been log4jremoved, and the spring-cloud-stream-binder-kafkadependency used in the project log4jneeds to be added manually:

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>

Source address:http://www.wisely.top/2018/02/28/springboot2-upgrade/

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326201456&siteId=291194637