From 3813afbfb12d745281eedbb4486f5ee35c4ab0e5 Mon Sep 17 00:00:00 2001 From: "zhang.hang" <2740277548@qq.com> Date: Sun, 13 Oct 2019 17:28:39 +0800 Subject: [PATCH 1/4] =?UTF-8?q?Springboot=E6=A0=B9=E6=8D=AE=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E7=8E=AF=E5=A2=83=E6=89=93=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Springboot-DifferentEnv-Pack/README.MD | 4 + Springboot-DifferentEnv-Pack/pom.xml | 141 ++++++++++++++++++ .../pack/SpringBootPackApplication.java | 11 ++ .../src/main/resources/123.txt | 1 + .../src/main/resources/application.yml | 3 + .../resources/env/dev/application-dev.yml | 9 ++ .../src/main/resources/env/dev/logback.xml | 14 ++ .../resources/env/prd/application-prd.yml | 8 + .../src/main/resources/env/prd/logback.xml | 30 ++++ .../resources/env/stg/application-stg.yml | 9 ++ .../src/main/resources/env/stg/logback.xml | 14 ++ .../main/resources/mybatis/mapper/test.xml | 1 + 12 files changed, 245 insertions(+) create mode 100644 Springboot-DifferentEnv-Pack/README.MD create mode 100644 Springboot-DifferentEnv-Pack/pom.xml create mode 100644 Springboot-DifferentEnv-Pack/src/main/java/com/button/pack/SpringBootPackApplication.java create mode 100644 Springboot-DifferentEnv-Pack/src/main/resources/123.txt create mode 100644 Springboot-DifferentEnv-Pack/src/main/resources/application.yml create mode 100644 Springboot-DifferentEnv-Pack/src/main/resources/env/dev/application-dev.yml create mode 100644 Springboot-DifferentEnv-Pack/src/main/resources/env/dev/logback.xml create mode 100644 Springboot-DifferentEnv-Pack/src/main/resources/env/prd/application-prd.yml create mode 100644 Springboot-DifferentEnv-Pack/src/main/resources/env/prd/logback.xml create mode 100644 Springboot-DifferentEnv-Pack/src/main/resources/env/stg/application-stg.yml create mode 100644 Springboot-DifferentEnv-Pack/src/main/resources/env/stg/logback.xml create mode 100644 Springboot-DifferentEnv-Pack/src/main/resources/mybatis/mapper/test.xml diff --git a/Springboot-DifferentEnv-Pack/README.MD b/Springboot-DifferentEnv-Pack/README.MD new file mode 100644 index 0000000..7bf4a08 --- /dev/null +++ b/Springboot-DifferentEnv-Pack/README.MD @@ -0,0 +1,4 @@ +# 该案例用于演示不用环境打包 +clean package -Pdev 开发环境 +clean package -Pstg 测试环境 +clean package -Pprd 生产环境 \ No newline at end of file diff --git a/Springboot-DifferentEnv-Pack/pom.xml b/Springboot-DifferentEnv-Pack/pom.xml new file mode 100644 index 0000000..e9768c2 --- /dev/null +++ b/Springboot-DifferentEnv-Pack/pom.xml @@ -0,0 +1,141 @@ + + 4.0.0 + com.button + Springboot-DifferentEnv-Pack + 0.0.1-SNAPSHOT + jar + + + UTF-8 + UTF-8 + 1.8 + + + org.springframework.boot + spring-boot-starter-parent + 2.0.1.RELEASE + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-devtools + true + true + + + + + + dev + + dev + + + + true + + + + + stg + + stg + + + + + prd + + prd + + + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + + true + + com.button.pack.SpringBootPackApplication + + + + + repackage + + + + + + maven-resources-plugin + + UTF-8 + true + + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + org.springframework.boot + spring-boot-maven-plugin + + -Dfile.encoding=UTF-8 + true + + + + + + + src/main/resources + + + + env/* + + + mybatis/mapper/* + *.txt + + + + + src/main/resources + + true + + application.yml + + + + src/main/resources/env/${profiles.active} + true + + + + \ No newline at end of file diff --git a/Springboot-DifferentEnv-Pack/src/main/java/com/button/pack/SpringBootPackApplication.java b/Springboot-DifferentEnv-Pack/src/main/java/com/button/pack/SpringBootPackApplication.java new file mode 100644 index 0000000..0e49040 --- /dev/null +++ b/Springboot-DifferentEnv-Pack/src/main/java/com/button/pack/SpringBootPackApplication.java @@ -0,0 +1,11 @@ +package com.button.pack; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringBootPackApplication { + public static void main(String[] args) { + SpringApplication.run(SpringBootPackApplication.class, args); + } +} diff --git a/Springboot-DifferentEnv-Pack/src/main/resources/123.txt b/Springboot-DifferentEnv-Pack/src/main/resources/123.txt new file mode 100644 index 0000000..63a9c0c --- /dev/null +++ b/Springboot-DifferentEnv-Pack/src/main/resources/123.txt @@ -0,0 +1 @@ +这只是为了演示,没有用处 \ No newline at end of file diff --git a/Springboot-DifferentEnv-Pack/src/main/resources/application.yml b/Springboot-DifferentEnv-Pack/src/main/resources/application.yml new file mode 100644 index 0000000..1e3e67f --- /dev/null +++ b/Springboot-DifferentEnv-Pack/src/main/resources/application.yml @@ -0,0 +1,3 @@ +spring: + profiles: + active: @profiles.active@ \ No newline at end of file diff --git a/Springboot-DifferentEnv-Pack/src/main/resources/env/dev/application-dev.yml b/Springboot-DifferentEnv-Pack/src/main/resources/env/dev/application-dev.yml new file mode 100644 index 0000000..94b6a10 --- /dev/null +++ b/Springboot-DifferentEnv-Pack/src/main/resources/env/dev/application-dev.yml @@ -0,0 +1,9 @@ +server: + servlet: + context-path: /pack + port: 8080 + uri-encoding: utf-8 + +logging: + file: logback.xml + \ No newline at end of file diff --git a/Springboot-DifferentEnv-Pack/src/main/resources/env/dev/logback.xml b/Springboot-DifferentEnv-Pack/src/main/resources/env/dev/logback.xml new file mode 100644 index 0000000..9813886 --- /dev/null +++ b/Springboot-DifferentEnv-Pack/src/main/resources/env/dev/logback.xml @@ -0,0 +1,14 @@ + + + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} -%msg%n + + + + + + + \ No newline at end of file diff --git a/Springboot-DifferentEnv-Pack/src/main/resources/env/prd/application-prd.yml b/Springboot-DifferentEnv-Pack/src/main/resources/env/prd/application-prd.yml new file mode 100644 index 0000000..b20c86b --- /dev/null +++ b/Springboot-DifferentEnv-Pack/src/main/resources/env/prd/application-prd.yml @@ -0,0 +1,8 @@ +server: + servlet: + context-path: /pack + port: 8082 + uri-encoding: utf-8 + +logging: + file: logback.xml diff --git a/Springboot-DifferentEnv-Pack/src/main/resources/env/prd/logback.xml b/Springboot-DifferentEnv-Pack/src/main/resources/env/prd/logback.xml new file mode 100644 index 0000000..a38ed88 --- /dev/null +++ b/Springboot-DifferentEnv-Pack/src/main/resources/env/prd/logback.xml @@ -0,0 +1,30 @@ + + + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} -%msg%n + + + + ${LOG_HOME}/springboot_pack.log + + + ${LOG_HOME}/springboot_pack.log.%d{yyyy-MM-dd}.%i.log + + + 100MB + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{50} -%msg%n + + + + + + + + \ No newline at end of file diff --git a/Springboot-DifferentEnv-Pack/src/main/resources/env/stg/application-stg.yml b/Springboot-DifferentEnv-Pack/src/main/resources/env/stg/application-stg.yml new file mode 100644 index 0000000..6adeefc --- /dev/null +++ b/Springboot-DifferentEnv-Pack/src/main/resources/env/stg/application-stg.yml @@ -0,0 +1,9 @@ +server: + servlet: + context-path: /pack + port: 8081 + uri-encoding: utf-8 + +logging: + file: logback.xml + \ No newline at end of file diff --git a/Springboot-DifferentEnv-Pack/src/main/resources/env/stg/logback.xml b/Springboot-DifferentEnv-Pack/src/main/resources/env/stg/logback.xml new file mode 100644 index 0000000..9813886 --- /dev/null +++ b/Springboot-DifferentEnv-Pack/src/main/resources/env/stg/logback.xml @@ -0,0 +1,14 @@ + + + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} -%msg%n + + + + + + + \ No newline at end of file diff --git a/Springboot-DifferentEnv-Pack/src/main/resources/mybatis/mapper/test.xml b/Springboot-DifferentEnv-Pack/src/main/resources/mybatis/mapper/test.xml new file mode 100644 index 0000000..b994f53 --- /dev/null +++ b/Springboot-DifferentEnv-Pack/src/main/resources/mybatis/mapper/test.xml @@ -0,0 +1 @@ + \ No newline at end of file -- Gitee From a000e6641b49bd711fe42d08a69d0179c7b6cc4a Mon Sep 17 00:00:00 2001 From: "zhang.hang" <2740277548@qq.com> Date: Sun, 13 Oct 2019 17:30:07 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=88=A9=E7=94=A8spring-session=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0session=E5=85=B1=E4=BA=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Springboot-Springsession/README.MD | 3 + Springboot-Springsession/pom.xml | 68 +++++++++++++++++++ .../session/SpringBootSessionApplication.java | 11 +++ .../session/controller/SessionController.java | 20 ++++++ .../controller/config/RedisSessionConfig.java | 10 +++ .../src/main/resources/application.yml | 14 ++++ .../src/main/resources/logback.xml | 30 ++++++++ 7 files changed, 156 insertions(+) create mode 100644 Springboot-Springsession/README.MD create mode 100644 Springboot-Springsession/pom.xml create mode 100644 Springboot-Springsession/src/main/java/com/button/session/SpringBootSessionApplication.java create mode 100644 Springboot-Springsession/src/main/java/com/button/session/controller/SessionController.java create mode 100644 Springboot-Springsession/src/main/java/com/button/session/controller/config/RedisSessionConfig.java create mode 100644 Springboot-Springsession/src/main/resources/application.yml create mode 100644 Springboot-Springsession/src/main/resources/logback.xml diff --git a/Springboot-Springsession/README.MD b/Springboot-Springsession/README.MD new file mode 100644 index 0000000..75d0ae7 --- /dev/null +++ b/Springboot-Springsession/README.MD @@ -0,0 +1,3 @@ +# 该案例用于演示Springboot整合Springsession实现session共享 +http://localhost:8080/session/sessions +关于启动异常:https://blog.csdn.net/oarsman/article/details/52801877 \ No newline at end of file diff --git a/Springboot-Springsession/pom.xml b/Springboot-Springsession/pom.xml new file mode 100644 index 0000000..3bc1d80 --- /dev/null +++ b/Springboot-Springsession/pom.xml @@ -0,0 +1,68 @@ + + 4.0.0 + com.button + Springboot-Springsession + 0.0.1-SNAPSHOT + jar + + + UTF-8 + UTF-8 + 1.8 + + + org.springframework.boot + spring-boot-starter-parent + 2.0.1.RELEASE + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-data-redis + + + org.springframework.session + spring-session-data-redis + + + org.quartz-scheduler + quartz-jobs + + + org.quartz-scheduler + quartz + + + org.springframework + spring-context + + + + + org.springframework.boot + spring-boot-devtools + true + true + + + + + + org.springframework.boot + spring-boot-maven-plugin + + -Dfile.encoding=UTF-8 + true + + + + + \ No newline at end of file diff --git a/Springboot-Springsession/src/main/java/com/button/session/SpringBootSessionApplication.java b/Springboot-Springsession/src/main/java/com/button/session/SpringBootSessionApplication.java new file mode 100644 index 0000000..807074f --- /dev/null +++ b/Springboot-Springsession/src/main/java/com/button/session/SpringBootSessionApplication.java @@ -0,0 +1,11 @@ +package com.button.session; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringBootSessionApplication { + public static void main(String[] args) { + SpringApplication.run(SpringBootSessionApplication.class, args); + } +} diff --git a/Springboot-Springsession/src/main/java/com/button/session/controller/SessionController.java b/Springboot-Springsession/src/main/java/com/button/session/controller/SessionController.java new file mode 100644 index 0000000..c86115b --- /dev/null +++ b/Springboot-Springsession/src/main/java/com/button/session/controller/SessionController.java @@ -0,0 +1,20 @@ +package com.button.session.controller; + +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class SessionController { + @GetMapping(value = "/sessions") + public Object sessions(HttpServletRequest request) { + Map map = new HashMap<>(); + map.put("sessionId", request.getSession().getId()); + map.put("message", request.getSession().getAttribute("map")); + return map; + } +} diff --git a/Springboot-Springsession/src/main/java/com/button/session/controller/config/RedisSessionConfig.java b/Springboot-Springsession/src/main/java/com/button/session/controller/config/RedisSessionConfig.java new file mode 100644 index 0000000..6e0d198 --- /dev/null +++ b/Springboot-Springsession/src/main/java/com/button/session/controller/config/RedisSessionConfig.java @@ -0,0 +1,10 @@ +package com.button.session.controller.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; + +@Configuration +@EnableRedisHttpSession +public class RedisSessionConfig { + +} diff --git a/Springboot-Springsession/src/main/resources/application.yml b/Springboot-Springsession/src/main/resources/application.yml new file mode 100644 index 0000000..225ea69 --- /dev/null +++ b/Springboot-Springsession/src/main/resources/application.yml @@ -0,0 +1,14 @@ +server: + servlet: + context-path: /session + port: 8080 + uri-encoding: utf-8 + +logging: + file: logback.xml + +spring: + redis: + host: www.radiobutton.shop + port: 6379 + password: 940126zhzh \ No newline at end of file diff --git a/Springboot-Springsession/src/main/resources/logback.xml b/Springboot-Springsession/src/main/resources/logback.xml new file mode 100644 index 0000000..d0e39f8 --- /dev/null +++ b/Springboot-Springsession/src/main/resources/logback.xml @@ -0,0 +1,30 @@ + + + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} -%msg%n + + + + ${LOG_HOME}/springboot_session.log + + + ${LOG_HOME}/springboot_session.log.%d{yyyy-MM-dd}.%i.log + + + 100MB + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{50} -%msg%n + + + + + + + + \ No newline at end of file -- Gitee From 87f6d914cbc9e158ba7a77832ffff942373f5eff Mon Sep 17 00:00:00 2001 From: "zhang.hang" <2740277548@qq.com> Date: Sun, 13 Oct 2019 17:32:06 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Springboot-DifferentEnv-Pack/README.MD | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Springboot-DifferentEnv-Pack/README.MD b/Springboot-DifferentEnv-Pack/README.MD index 7bf4a08..793a337 100644 --- a/Springboot-DifferentEnv-Pack/README.MD +++ b/Springboot-DifferentEnv-Pack/README.MD @@ -1,4 +1,4 @@ # 该案例用于演示不用环境打包 -clean package -Pdev 开发环境 -clean package -Pstg 测试环境 -clean package -Pprd 生产环境 \ No newline at end of file +clean package -Pdev 开发环境 +clean package -Pstg 测试环境 +clean package -Pprd 生产环境 \ No newline at end of file -- Gitee From 5ec5abafb97c7e7b200e518e1e1bb8f98f5e5b54 Mon Sep 17 00:00:00 2001 From: "zhang.hang" <2740277548@qq.com> Date: Sun, 13 Oct 2019 17:33:45 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 43088be..d0a8eb9 100644 --- a/README.md +++ b/README.md @@ -20,4 +20,6 @@ SpringBoot应用集合 - [Springboot配置全局异常](https://gitee.com/superbutton/SpringBoot-Components/tree/develop/Springboot-Exception) - [SpringBoot集成阿里巴巴Druid监控](https://gitee.com/superbutton/SpringBoot-Components/tree/develop/Springboot-Druid) - [SpringBoot整合Httpclient](https://gitee.com/superbutton/SpringBoot-Components/tree/develop/Springboot-Httpclient) -- [SpringBoot-Admin实现监控](https://gitee.com/superbutton/SpringBoot-Components/tree/develop/SpringBoot-Admin-Parent) \ No newline at end of file +- [SpringBoot-Admin实现监控](https://gitee.com/superbutton/SpringBoot-Components/tree/develop/SpringBoot-Admin-Parent) +- [SpringBoot不同环境打包配置](https://gitee.com/superbutton/SpringBoot-Components/tree/develop/Springboot-Springsession) +- [SpringBoot利用springsession实现session共享](https://gitee.com/superbutton/SpringBoot-Components/tree/develop/Springboot-Springsession) \ No newline at end of file -- Gitee