spring boot 1.5升级到2.X版本 变动

spring boot 1.5升级到2.1版本变动

spring boot老版本1.5.5  

spring boot新版本2.1.3

redis变动:

org.springframework.boot:spring-boot-starter-data-redis 变为 org.springframework.data:spring-data-redis (版本2.1.5.RELEASE)

 


org.springframework.data
spring-data-redis

然而在springboot2.x中,RedisCacheManager已经没有了单参数的构造方法

 

@Bean
public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig().entryTtl(null);
return RedisCacheManager.builder(RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory)).cacheDefaults(redisCacheConfiguration)
.build();

 

}

 

@Bean
@SuppressWarnings({ "rawtypes", "unchecked" })
public RedisTemplate redisTemplate(RedisConnectionFactory factory) {
RedisTemplate redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(factory);
// 使用Jackson2JsonRedisSerializer替换默认的序列化规则
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(objectMapper);
// 设置value的序列化规则
redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
// 设置key的序列化规则
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
}

 

 

feign 变动:

 2.x版本后,Spring Cloud对Feign的支持由spring-cloud-netflix-core 移到 spring-cloud-openfeign-core下 (版本2.1.0.RELEASE)

 


org.springframework.cloud
spring-cloud-starter-openfeign

 

spring cloud变动:

spring-cloud-dependencies 版本从Edgware.SR5版本 变为Greenwich.RELEASE版本

 





org.springframework.cloud
spring-cloud-dependencies
Greenwich.RELEASE
pom
import


 

jdbc驱动变动:

org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder 改为  org.springframework.boot.jdbc.DataSourceBuilder

 

你可能感兴趣的:(java,spring-cloud,spring-boot)