springboot集成springsession

xiaoxiao2021-02-28  7

@SpringBootApplication public class SpringsessionApplication { public static void main(String[] args) { SpringApplication.run(SpringsessionApplication.class, args); } } `` @RestController public class SessionController { // 用于测试 SpringBoot 容器是否启动 // http:localhost:8080/test @RequestMapping("/test") public String test(){ return "PING OK"; } // http:localhost:8080/put?key=name&value=liwei @RequestMapping("/put") public String put(HttpSession session, @RequestParam("key") String key, @RequestParam("value") String value){ session.setAttribute(key,value); return "PUT OK"; } // http:localhost:8080/get?key=name @RequestMapping("/get") public String get(HttpSession session, @RequestParam("key") String key){ String value = (String) session.getAttribute(key); if(value == null || "".equals(value)){ return "NO VALUE GET"; } return value; } }

@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 60) public class SessionConfig {

}

spring.redis.database=0 spring.redis.host=127.0.0.1 spring.redis.port=6379 spring.redis.password= # 连接池最大连接数 spring.redis.pool.max-active=8 spring.redis.pool.max-wait=-1 # 连接池中的最大空闲连接 spring.redis.pool.max-idle=8 # 连接池中的最小空闲连接 spring.redis.pool.min-idle=0 # 连接超时时间(毫秒) spring.redis.timeout=5000

参考博客:https://blog.csdn.net/lw_power/article/details/46843489 https://blog.csdn.net/wu6660563/article/details/78698957 “` 项目地址

转载请注明原文地址: https://www.6miu.com/read-2400105.html

最新回复(0)