我在springboot项目中采用 --RedisTemplate--来配置redis的时候一直出现,方法内部报错。
具体原因
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
(springboot 的maven依赖包中默认的springboot依赖)
Mave使用的spring-boot-starter-parent会使项目加入一些默认配置。这个parent提供了以下特性:
默认使用Java 8
使用UTF-8编码
一个引用管理的功能,在dependencies里的部分配置可以不用填写version信息,这些version信息会从spring-boot-dependencies里得到继承。
识别过来资源过滤(Sensible resource filtering.)
识别插件的配置(Sensible plugin configuration (exec plugin, surefire, Git commit ID, shade).)
能够识别application.properties和application.yml类型的文件,同时也能支持profile-specific类型的文件(如: application-foo.properties and application-foo.yml,这个功能可以更好的配置不同生产环境下的配置文件)。
maven把默认的占位符${…}改为了@..@(这点大家还是看下原文自己理解下吧,我个人用的也比较少
since the default config files accept Spring style placeholders (${…}) the Maven filtering is changed to use @..@ placeholders (you can override that with a Maven property resource.delimiter).)
导致在配置 spring-boot-starter-data-redis依赖 RedisTemplate方式控制redis的时候会出现版本配置问题
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
对应的jar包依赖只能是 1.5.8版本的,当默认新建的版本是2.0.以上时会出现配置异常
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>