1. Background
The original
Spring Boot
version of the project is1.5.4.RELEASE
,Spring Cloud
version isDalston.SR2
, and the upgradedSpring Boot
version is2.0.0.M7
,Spring Cloud
version isFinchley.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
Oauth2
protocol specification, and the authenticatedToken
token is usedRedis
for 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.M7
The automatic configurationautoconfigure
in the referenceResourceServer
has been removed and will be moved to theSpring Security
project. The current alternative is to usehttps://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
RedisTokenStore
theNoSuchMethodError RedisConnection.set([B[B)V
error that occurs, the current solution is to rewriteRedisTokenStore
line 160 andconn.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 API
andElasticSearch
interacting with it, the project wasSpring Data Elasticsearch
switched from the original toSpring Data Jest
theElasticSearch
client.
- 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
Feign
as aRest
client for remote calls. After theSpring Cloud
version is upgraded, theFeign
dependencies are changed to:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
5. log4j
Spring Boot 2.0.0.M7
The dependency has beenlog4j
removed, and thespring-cloud-stream-binder-kafka
dependency used in the projectlog4j
needs 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/