<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> <version>1.5.2.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.session</groupId> <artifactId>spring-session-data-redis</artifactId> <version>1.3.0.RELEASE</version> </dependency>
# Redis配置 spring.session.store-type=redis spring.redis.database=0 spring.redis.host=localhost spring.redis.port=6379
@SpringBootApplication
@EnableRedisHttpSession
@RestController
public class DemoApplication {
private Logger logger = LoggerFactory.getLogger(this.getClass());
public static void main(String[] args) {
SpringApplication app = new SpringApplication(DemoApplication.class);
app.setWebEnvironment(true);
app.run(args);
}
@GetMapping("/hello")
public ResponseEntity<?> hello(HttpSession session) {
if (session.isNew()) {
logger.info("Successfully creates a session ,the id of session :" + session.getId());
session.setAttribute("key", "hello");
} else {
logger.info("session already exists in the server, the id of session :"+ session.getId());
logger.info(session.getAttribute("key").toString());
}
return new ResponseEntity<>("Hello World", HttpStatus.OK);
}
}
redis-cli
127.0.0.1:6379> keys * (empty list or set)
2017-06-12 00:26:12.601 INFO 9580 — [nio-8080-exec-1] ication$$EnhancerBySpringCGLIB$$de942542 : Successfully creates a session ,the id of session :4368a535-9bfa-406b-975c-e58c2bca1e75
2017-06-12 00:30:43.533 INFO 9580 — [nio-8080-exec-5] ication$$EnhancerBySpringCGLIB$$de942542 : session already exists in the server, the id of session :4368a535-9bfa-406b-975c-e58c2bca1e75 2017-06-12 00:30:43.533 INFO 9580 — [nio-8080-exec-5] ication$$EnhancerBySpringCGLIB$$de942542 : hello
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有