更新Spring5之后遇到的小问题

    今天更新了SpringBoot的配置,升级到了Spring5.0,然而升级之后发现报了很多的错误,很多之前的接口报错,部分接口甚至找不到了,经过排查发现了Maven test的好用之处,顺利发现了罪魁祸首是部分jar包在下载到本地仓库的时候有问题并不能打开,删除掉之后重新下载就搞定啦(运行springboot的时候报找不到classes的错误,但实际这个classes是存在的,排查之后也是同样的问题)。
    而且spring对redis的支持好像也进行了很大的改动,有方法没有了,也有方法过时啦,稍微修改了一下,把改过之后的代码贴上来看一看。    
    
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisPassword;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;

import com.typesafe.config.ConfigFactory;

/**
 * 使用缓存来帮助那些使用了复杂的查询条件而且频繁的查询
 * 
 * @author 15293
 *
 */
@Configuration
@EnableCaching
public class JftConfiguration {

	String host = ConfigFactory.load().getString("redis.ip");
	String port = ConfigFactory.load().getString("redis.port");
	String password = ConfigFactory.load().getString("redis.password");

	@Bean
	public CacheManager cacheManager(RedisConnectionFactory connectionFactory) {
		System.err.println("使用redis缓存管理器");
		return RedisCacheManager.create(connectionFactory);
	}

	@Bean
	public JedisConnectionFactory redisConnectionFactory() {
		RedisStandaloneConfiguration redisConfiguration = new RedisStandaloneConfiguration(host,
				Integer.parseInt(port));
		RedisPassword redisPassword = RedisPassword.of(password);
		redisConfiguration.setPassword(redisPassword);
		JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(redisConfiguration);
		jedisConnectionFactory.afterPropertiesSet();
		return jedisConnectionFactory;
	}

	@Bean
	public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) {
		RedisTemplate redisTemplate = new RedisTemplate();
		redisTemplate.setConnectionFactory(redisConnectionFactory);
		redisTemplate.afterPropertiesSet();
		return redisTemplate;
	}
}

记得同时也要更新 The Spring IO platform,不然更新了新的包但去找老的会报很多class文件找不到的。

    
        
            io.spring.platform
            platform-bom
            Cairo-RC1
            pom
            import
        
    

    
        spring-milestones
        Spring Milestones
        https://repo.spring.io/libs-milestone
        
            false
        
    

你可能感兴趣的:(springboot)