##使用Spring Boot与Redis集成时出现java.lang.NoClassDefFoundError: org/springframework/data/redis/connection/RedisConnectionFactory
最近按照教程指引,给Spring应用加入了授权领英账号登录的界面。
接着准备与Redis集成,也就是将登录的用户信息存储到分布式数据库Redis中。基本步骤就是这么几步:
build.gradle中添加:
compile('org.springframework.boot:spring-boot-starter-redis')
compile('org.springframework.session:spring-session:1.0.1.RELEASE')
新建application-redis.properties:
spring.redis.host=localhost
spring.redis.port=6379
创建RedisConfig:
@Configuration
@Profile("redis")
@EnableRedisHttpSession
public class RedisConfig {
}
结果运行的时候报了java.lang.NoClassDefFoundError: org/springframework/data/redis/connection/RedisConnectionFactory这么个错。后来一看External Libraries里,压根没有spring-boot-starter-redis这个依赖,原来是包没引对!到Maven中央仓库里查找,在build.gradle里补上版本号,问题解决: compile('org.springframework.boot:spring-boot-starter-redis:1.3.1.RELEASE')
费了好久解决了问题,感觉还是对Gradle构建过程不够清楚,到项目里找了半天错误。