diff --git a/README.md b/README.md index 3cd2581..86fb0fb 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # spring-boot-study -Spring Boot教程源码,博客地址:https://blog.csdn.net/gnail_oug + diff --git a/pom.xml b/pom.xml index 198953e..3196c51 100644 --- a/pom.xml +++ b/pom.xml @@ -28,6 +28,7 @@ spring-boot-scheduling spring-boot-quartz spring-boot-quartz-db + spring-boot-session-share diff --git a/spring-boot-session-share/pom.xml b/spring-boot-session-share/pom.xml new file mode 100644 index 0000000..5700d57 --- /dev/null +++ b/spring-boot-session-share/pom.xml @@ -0,0 +1,12 @@ + + + 4.0.0 + + stayblank + spring-boot-session-share + 1.0-SNAPSHOT + + + \ No newline at end of file diff --git a/spring-boot-session-share/src/main/java/com/stayblank/springboot/Application.java b/spring-boot-session-share/src/main/java/com/stayblank/springboot/Application.java new file mode 100644 index 0000000..2dde7ee --- /dev/null +++ b/spring-boot-session-share/src/main/java/com/stayblank/springboot/Application.java @@ -0,0 +1,18 @@ +package com.songguoliang.springboot; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableScheduling; + +/** + * @Description + * @Author sgl + * @Date 2018-06-26 10:02 + */ +@EnableScheduling +@SpringBootApplication +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class); + } +} diff --git a/spring-boot-session-share/src/main/java/com/stayblank/springboot/RedisSessionConfig.java b/spring-boot-session-share/src/main/java/com/stayblank/springboot/RedisSessionConfig.java new file mode 100644 index 0000000..78cda58 --- /dev/null +++ b/spring-boot-session-share/src/main/java/com/stayblank/springboot/RedisSessionConfig.java @@ -0,0 +1,11 @@ +package stayblank; + +import org.springframework.context.annotation.Configuration; +import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; + +@Configuration +//maxInactiveIntervalInSeconds 默认是1800秒过期,这里测试修改为60秒 +@EnableRedisHttpSession(maxInactiveIntervalInSeconds=60) +public class RedisSessionConfig{ + +} diff --git a/spring-boot-session-share/src/main/java/com/stayblank/springboot/TestController.java b/spring-boot-session-share/src/main/java/com/stayblank/springboot/TestController.java new file mode 100644 index 0000000..90e1d96 --- /dev/null +++ b/spring-boot-session-share/src/main/java/com/stayblank/springboot/TestController.java @@ -0,0 +1,27 @@ +package stayblank; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.servlet.http.HttpServletRequest; + + +@Controller +@RequestMapping("/") +public class TestController { + + @RequestMapping(value="/getSessionId") + @ResponseBody + public String getSessionId(HttpServletRequest request){ + + Object o = request.getSession().getAttribute("springboot"); + if(o == null){ + o = "spring boot 牛逼了!!!有端口"+request.getLocalPort()+"生成"; + request.getSession().setAttribute("springboot", o); + } + + return "端口=" + request.getLocalPort() + " sessionId=" + request.getSession().getId() +"
"+o; + } + +} diff --git a/spring-boot-session-share/src/resources/application.yml b/spring-boot-session-share/src/resources/application.yml new file mode 100644 index 0000000..eacb541 --- /dev/null +++ b/spring-boot-session-share/src/resources/application.yml @@ -0,0 +1,14 @@ + +server: + port: 8080 + session-timeout: 60 + +spring: + redis: + database: 0 + host: 192.168.207.3 + port: 6379 + password: 123456 + + session: + store-type: none \ No newline at end of file