一、pom.xml的配置
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
二、建立redis的配置文件
RedisProperty.java
代码如下:
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
@Configuration
public class RedisProperty {
String host = "hdp01.pcl-test.com";
int port = 6379;
String password = "pcl@2020";
@Bean
@Primary
/**覆盖掉默认的RedisProperties*/
public RedisProperties setRedisConfig() {
RedisProperties config = new RedisProperties();
config.setHost(host);
config.setPort(port);
config.setPassword(password);
return config;
}
}
三、在启动类上添加注解@EnableRedisHttpSession(redisNamespace = "PermissionService:session")
代码 详细参见 上传的资源文件