From ad78ed79109bf16b5573071b4edd2605d353b660 Mon Sep 17 00:00:00 2001 From: macro Date: Wed, 23 Oct 2019 16:40:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Spring=20Cloud=20Config?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=B8=AD=E5=BF=83=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mall-admin/pom.xml | 4 ++ .../src/main/resources/application-dev.yml | 29 --------- .../src/main/resources/application-prod.yml | 16 ----- mall-admin/src/main/resources/application.yml | 52 ++++++++-------- .../src/main/resources/bootstrap-dev.yml | 13 ++++ .../src/main/resources/bootstrap-prod.yml | 13 ++++ mall-admin/src/main/resources/bootstrap.yml | 5 ++ mall-config/.gitignore | 31 ++++++++++ mall-config/pom.xml | 38 ++++++++++++ .../com/macro/mall/MallConfigApplication.java | 17 ++++++ .../src/main/resources/application.yml | 16 +++++ .../main/resources/config/admin/admin-dev.yml | 21 +++++++ .../resources/config/admin/admin-prod.yml | 19 ++++++ .../main/resources/config/demo/demo-dev.yml | 10 ++++ .../main/resources/config/demo/demo-prod.yml | 7 +++ .../resources/config/portal/portal-dev.yml | 28 +++++++++ .../resources/config/portal/portal-prod.yml | 29 +++++++++ .../resources/config/search/search-dev.yml | 13 ++++ .../resources/config/search/search-prod.yml | 11 ++++ .../mall/MallConfigApplicationTests.java | 16 +++++ mall-demo/pom.xml | 6 +- mall-demo/src/main/resources/application.yml | 19 +----- .../src/main/resources/bootstrap-dev.yml | 13 ++++ .../src/main/resources/bootstrap-prod.yml | 13 ++++ mall-demo/src/main/resources/bootstrap.yml | 5 ++ mall-portal/pom.xml | 4 ++ .../mall/portal/config/TomcatConfig.java | 32 ---------- .../src/main/resources/application-dev.yml | 59 ------------------- .../src/main/resources/application-https.yml | 52 ---------------- .../src/main/resources/application-prod.yml | 42 ------------- .../src/main/resources/application.yml | 57 +++++++++++++++--- .../src/main/resources/bootstrap-dev.yml | 13 ++++ .../src/main/resources/bootstrap-prod.yml | 13 ++++ mall-portal/src/main/resources/bootstrap.yml | 5 ++ mall-search/pom.xml | 4 ++ .../src/main/resources/application-dev.yml | 33 ----------- .../src/main/resources/application-prod.yml | 23 -------- .../src/main/resources/application.yml | 40 +++++++++---- .../src/main/resources/bootstrap-dev.yml | 13 ++++ .../src/main/resources/bootstrap-prod.yml | 13 ++++ mall-search/src/main/resources/bootstrap.yml | 5 ++ pom.xml | 1 + 42 files changed, 502 insertions(+), 351 deletions(-) delete mode 100644 mall-admin/src/main/resources/application-dev.yml delete mode 100644 mall-admin/src/main/resources/application-prod.yml create mode 100644 mall-admin/src/main/resources/bootstrap-dev.yml create mode 100644 mall-admin/src/main/resources/bootstrap-prod.yml create mode 100644 mall-admin/src/main/resources/bootstrap.yml create mode 100644 mall-config/.gitignore create mode 100644 mall-config/pom.xml create mode 100644 mall-config/src/main/java/com/macro/mall/MallConfigApplication.java create mode 100644 mall-config/src/main/resources/application.yml create mode 100644 mall-config/src/main/resources/config/admin/admin-dev.yml create mode 100644 mall-config/src/main/resources/config/admin/admin-prod.yml create mode 100644 mall-config/src/main/resources/config/demo/demo-dev.yml create mode 100644 mall-config/src/main/resources/config/demo/demo-prod.yml create mode 100644 mall-config/src/main/resources/config/portal/portal-dev.yml create mode 100644 mall-config/src/main/resources/config/portal/portal-prod.yml create mode 100644 mall-config/src/main/resources/config/search/search-dev.yml create mode 100644 mall-config/src/main/resources/config/search/search-prod.yml create mode 100644 mall-config/src/test/java/com/macro/mall/MallConfigApplicationTests.java create mode 100644 mall-demo/src/main/resources/bootstrap-dev.yml create mode 100644 mall-demo/src/main/resources/bootstrap-prod.yml create mode 100644 mall-demo/src/main/resources/bootstrap.yml delete mode 100644 mall-portal/src/main/java/com/macro/mall/portal/config/TomcatConfig.java delete mode 100644 mall-portal/src/main/resources/application-dev.yml delete mode 100644 mall-portal/src/main/resources/application-https.yml delete mode 100644 mall-portal/src/main/resources/application-prod.yml create mode 100644 mall-portal/src/main/resources/bootstrap-dev.yml create mode 100644 mall-portal/src/main/resources/bootstrap-prod.yml create mode 100644 mall-portal/src/main/resources/bootstrap.yml delete mode 100644 mall-search/src/main/resources/application-dev.yml delete mode 100644 mall-search/src/main/resources/application-prod.yml create mode 100644 mall-search/src/main/resources/bootstrap-dev.yml create mode 100644 mall-search/src/main/resources/bootstrap-prod.yml create mode 100644 mall-search/src/main/resources/bootstrap.yml diff --git a/mall-admin/pom.xml b/mall-admin/pom.xml index 0b440ba..214d760 100644 --- a/mall-admin/pom.xml +++ b/mall-admin/pom.xml @@ -36,6 +36,10 @@ org.springframework.cloud spring-cloud-starter-netflix-eureka-client + + org.springframework.cloud + spring-cloud-starter-config + io.jsonwebtoken jjwt diff --git a/mall-admin/src/main/resources/application-dev.yml b/mall-admin/src/main/resources/application-dev.yml deleted file mode 100644 index 8fdd9ce..0000000 --- a/mall-admin/src/main/resources/application-dev.yml +++ /dev/null @@ -1,29 +0,0 @@ -spring: - datasource: - url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai - username: root - password: root - druid: - initial-size: 5 #连接池初始化大小 - min-idle: 10 #最小空闲连接数 - max-active: 20 #最大连接数 - web-stat-filter: - exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" #不统计这些请求数据 - stat-view-servlet: #访问监控网页的登录用户名和密码 - login-username: druid - login-password: druid -eureka: - client: - register-with-eureka: true - fetch-registry: true - service-url: - defaultZone: http://localhost:8001/eureka/ - registry-fetch-interval-seconds: 10 -management: #开启SpringBoot Admin的监控 - endpoints: - web: - exposure: - include: '*' - endpoint: - health: - show-details: always \ No newline at end of file diff --git a/mall-admin/src/main/resources/application-prod.yml b/mall-admin/src/main/resources/application-prod.yml deleted file mode 100644 index 9707371..0000000 --- a/mall-admin/src/main/resources/application-prod.yml +++ /dev/null @@ -1,16 +0,0 @@ -spring: - datasource: - url: jdbc:mysql://db:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai - username: reader - password: 123456 - druid: - initial-size: 5 #连接池初始化大小 - min-idle: 10 #最小空闲连接数 - max-active: 20 #最大连接数 - web-stat-filter: - exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" #不统计这些请求数据 - stat-view-servlet: #访问监控网页的登录用户名和密码 - login-username: druid - login-password: druid -logging: - path: /var/logs #配置日志生成路径 \ No newline at end of file diff --git a/mall-admin/src/main/resources/application.yml b/mall-admin/src/main/resources/application.yml index b31c0c6..01ffcee 100644 --- a/mall-admin/src/main/resources/application.yml +++ b/mall-admin/src/main/resources/application.yml @@ -1,34 +1,38 @@ -spring: - profiles: - active: dev #默认为开发环境 - application: - name: mall-admin server: port: 8180 +spring: + datasource: + url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai + username: root + password: root + druid: + initial-size: 5 #连接池初始化大小 + min-idle: 10 #最小空闲连接数 + max-active: 20 #最大连接数 + web-stat-filter: + exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" #不统计这些请求数据 + stat-view-servlet: #访问监控网页的登录用户名和密码 + login-username: druid + login-password: druid + rabbitmq: #rabbitmq相关配置 + host: localhost + port: 5672 + username: guest + password: guest mybatis: mapper-locations: - classpath:dao/*.xml - classpath*:com/**/mapper/*.xml +management: #开启SpringBoot Admin的监控 + endpoints: + web: + exposure: + include: '*' + endpoint: + health: + show-details: always jwt: tokenHeader: Authorization #JWT存储的请求头 secret: mySecret #JWT加解密使用的密钥 expiration: 604800 #JWT的超期限时间(60*60*24) - tokenHead: Bearer #JWT负载中拿到开头 -aliyun: - oss: - endpoint: oss-cn-shenzhen.aliyuncs.com # oss对外服务的访问域名 - accessKeyId: test # 访问身份验证中用到用户标识 - accessKeySecret: test # 用户用于加密签名字符串和oss用来验证签名字符串的密钥 - bucketName: macro-oss # oss的存储空间 - policy: - expire: 300 # 签名有效期(S) - maxSize: 10 # 上传文件大小(M) - callback: http://39.98.190.128:8080/aliyun/oss/callback # 文件上传成功后的回调地址 - dir: - prefix: mall/images/ # 上传文件夹路径前缀 -logging: - level: - root: info #日志配置DEBUG,INFO,WARN,ERROR - com.macro.mall: debug -# file: demo_log.log #配置日志生成路径 -# path: /var/logs #配置日志文件名称 + tokenHead: Bearer #JWT负载中拿到开头 \ No newline at end of file diff --git a/mall-admin/src/main/resources/bootstrap-dev.yml b/mall-admin/src/main/resources/bootstrap-dev.yml new file mode 100644 index 0000000..d35a60c --- /dev/null +++ b/mall-admin/src/main/resources/bootstrap-dev.yml @@ -0,0 +1,13 @@ +spring: + cloud: + config: + profile: dev #启用环境名称 + label: master #分支名称 + name: admin #配置文件名称 + discovery: + enabled: true + service-id: mall-config +eureka: + client: + service-url: + defaultZone: http://localhost:8001/eureka/ \ No newline at end of file diff --git a/mall-admin/src/main/resources/bootstrap-prod.yml b/mall-admin/src/main/resources/bootstrap-prod.yml new file mode 100644 index 0000000..a2fedae --- /dev/null +++ b/mall-admin/src/main/resources/bootstrap-prod.yml @@ -0,0 +1,13 @@ +spring: + cloud: + config: + profile: prod #启用环境名称 + label: master #分支名称 + name: admin #配置文件名称 + discovery: + enabled: true + service-id: mall-config +eureka: + client: + service-url: + defaultZone: http://localhost:8001/eureka/ \ No newline at end of file diff --git a/mall-admin/src/main/resources/bootstrap.yml b/mall-admin/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..c61f29d --- /dev/null +++ b/mall-admin/src/main/resources/bootstrap.yml @@ -0,0 +1,5 @@ +spring: + profiles: + active: dev + application: + name: mall-admin \ No newline at end of file diff --git a/mall-config/.gitignore b/mall-config/.gitignore new file mode 100644 index 0000000..a2a3040 --- /dev/null +++ b/mall-config/.gitignore @@ -0,0 +1,31 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/** +!**/src/test/** + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ + +### VS Code ### +.vscode/ diff --git a/mall-config/pom.xml b/mall-config/pom.xml new file mode 100644 index 0000000..3cc12a9 --- /dev/null +++ b/mall-config/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + + com.macro.mall + mall-config + 0.0.1-SNAPSHOT + mall-config + mall-config project for mall + + + com.macro.mall + mall + 1.0-SNAPSHOT + + + + + org.springframework.cloud + spring-cloud-config-server + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/mall-config/src/main/java/com/macro/mall/MallConfigApplication.java b/mall-config/src/main/java/com/macro/mall/MallConfigApplication.java new file mode 100644 index 0000000..2c6c13d --- /dev/null +++ b/mall-config/src/main/java/com/macro/mall/MallConfigApplication.java @@ -0,0 +1,17 @@ +package com.macro.mall; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.config.server.EnableConfigServer; + +@EnableConfigServer +@EnableDiscoveryClient +@SpringBootApplication +public class MallConfigApplication { + + public static void main(String[] args) { + SpringApplication.run(MallConfigApplication.class, args); + } + +} diff --git a/mall-config/src/main/resources/application.yml b/mall-config/src/main/resources/application.yml new file mode 100644 index 0000000..0fa2248 --- /dev/null +++ b/mall-config/src/main/resources/application.yml @@ -0,0 +1,16 @@ +server: + port: 8301 +spring: + application: + name: mall-config + profiles: + active: native #使用本地配置 + cloud: + config: + server: + native: + search-locations: classpath:/config/{application} +eureka: + client: + service-url: + defaultZone: http://localhost:8001/eureka/ diff --git a/mall-config/src/main/resources/config/admin/admin-dev.yml b/mall-config/src/main/resources/config/admin/admin-dev.yml new file mode 100644 index 0000000..3395943 --- /dev/null +++ b/mall-config/src/main/resources/config/admin/admin-dev.yml @@ -0,0 +1,21 @@ +aliyun: + oss: + endpoint: oss-cn-shenzhen.aliyuncs.com # oss对外服务的访问域名 + accessKeyId: test # 访问身份验证中用到用户标识 + accessKeySecret: test # 用户用于加密签名字符串和oss用来验证签名字符串的密钥 + bucketName: macro-oss # oss的存储空间 + policy: + expire: 300 # 签名有效期(S) + maxSize: 10 # 上传文件大小(M) + callback: http://39.98.190.128:8080/aliyun/oss/callback # 文件上传成功后的回调地址 + dir: + prefix: mall/images/ # 上传文件夹路径前缀 +spring: + datasource: + url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai + username: root + password: root +logging: + level: + root: info #日志配置DEBUG,INFO,WARN,ERROR + com.macro.mall: debug \ No newline at end of file diff --git a/mall-config/src/main/resources/config/admin/admin-prod.yml b/mall-config/src/main/resources/config/admin/admin-prod.yml new file mode 100644 index 0000000..a0002db --- /dev/null +++ b/mall-config/src/main/resources/config/admin/admin-prod.yml @@ -0,0 +1,19 @@ +aliyun: + oss: + endpoint: oss-cn-shenzhen.aliyuncs.com # oss对外服务的访问域名 + accessKeyId: test # 访问身份验证中用到用户标识 + accessKeySecret: test # 用户用于加密签名字符串和oss用来验证签名字符串的密钥 + bucketName: macro-oss # oss的存储空间 + policy: + expire: 300 # 签名有效期(S) + maxSize: 10 # 上传文件大小(M) + callback: http://39.98.190.128:8080/aliyun/oss/callback # 文件上传成功后的回调地址 + dir: + prefix: mall/images/ # 上传文件夹路径前缀 +spring: + datasource: + url: jdbc:mysql://db:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai + username: reader + password: 123456 +logging: + path: /var/logs #配置日志生成路径 \ No newline at end of file diff --git a/mall-config/src/main/resources/config/demo/demo-dev.yml b/mall-config/src/main/resources/config/demo/demo-dev.yml new file mode 100644 index 0000000..6f0240f --- /dev/null +++ b/mall-config/src/main/resources/config/demo/demo-dev.yml @@ -0,0 +1,10 @@ +spring: + datasource: + url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai + username: root + password: root +logging: + level: + root: info #日志配置DEBUG,INFO,WARN,ERROR + com.macro.mall: debug + com.macro.mall.demo.service.FeignAdminService: debug \ No newline at end of file diff --git a/mall-config/src/main/resources/config/demo/demo-prod.yml b/mall-config/src/main/resources/config/demo/demo-prod.yml new file mode 100644 index 0000000..4e49a5f --- /dev/null +++ b/mall-config/src/main/resources/config/demo/demo-prod.yml @@ -0,0 +1,7 @@ +spring: + datasource: + url: jdbc:mysql://db:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai + username: reader + password: 123456 +logging: + path: /var/logs #配置日志生成路径 \ No newline at end of file diff --git a/mall-config/src/main/resources/config/portal/portal-dev.yml b/mall-config/src/main/resources/config/portal/portal-dev.yml new file mode 100644 index 0000000..c9b3a09 --- /dev/null +++ b/mall-config/src/main/resources/config/portal/portal-dev.yml @@ -0,0 +1,28 @@ +spring: + datasource: + url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai + username: root + password: root + data: + mongodb: + host: localhost + port: 27017 + database: mall-port + redis: + host: localhost # Redis服务器地址 + database: 0 # Redis数据库索引(默认为0) + port: 6379 # Redis服务器连接端口 + password: 123456 # Redis服务器连接密码(默认为空) + rabbitmq: + host: localhost + port: 5672 + virtual-host: /mall + username: mall + password: mall + publisher-confirms: true #如果对异步消息需要回调必须设置为true +# 日志配置 +logging: + level: + org.springframework.data.mongodb.core: debug + com.macro.mall.mapper: debug + com.macro.mall.portal.dao: debug \ No newline at end of file diff --git a/mall-config/src/main/resources/config/portal/portal-prod.yml b/mall-config/src/main/resources/config/portal/portal-prod.yml new file mode 100644 index 0000000..9dd3fe3 --- /dev/null +++ b/mall-config/src/main/resources/config/portal/portal-prod.yml @@ -0,0 +1,29 @@ +spring: + datasource: + url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai + username: root + password: root + data: + mongodb: + host: localhost + port: 27017 + database: mall-port + redis: + host: localhost # Redis服务器地址 + database: 0 # Redis数据库索引(默认为0) + port: 6379 # Redis服务器连接端口 + password: 123456 # Redis服务器连接密码(默认为空) + rabbitmq: + host: localhost + port: 5672 + virtual-host: /mall + username: mall + password: mall + publisher-confirms: true #如果对异步消息需要回调必须设置为true +# 日志配置 +logging: + level: + org.springframework.data.mongodb.core: debug + com.macro.mall.mapper: debug + com.macro.mall.portal.dao: debug + diff --git a/mall-config/src/main/resources/config/search/search-dev.yml b/mall-config/src/main/resources/config/search/search-dev.yml new file mode 100644 index 0000000..45ecdc8 --- /dev/null +++ b/mall-config/src/main/resources/config/search/search-dev.yml @@ -0,0 +1,13 @@ +spring: + datasource: + url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai + username: root + password: root + data: + elasticsearch: + cluster-nodes: 127.0.0.1:9300 + cluster-name: elasticsearch +logging: + level: + root: info #日志配置DEBUG,INFO,WARN,ERROR + com.macro.mall: debug \ No newline at end of file diff --git a/mall-config/src/main/resources/config/search/search-prod.yml b/mall-config/src/main/resources/config/search/search-prod.yml new file mode 100644 index 0000000..7d0c80a --- /dev/null +++ b/mall-config/src/main/resources/config/search/search-prod.yml @@ -0,0 +1,11 @@ +spring: + datasource: + url: jdbc:mysql://db:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai + username: reader + password: 123456 + data: + elasticsearch: + cluster-nodes: es:9300 + cluster-name: elasticsearch +logging: + path: /var/logs #配置日志生成路径 \ No newline at end of file diff --git a/mall-config/src/test/java/com/macro/mall/MallConfigApplicationTests.java b/mall-config/src/test/java/com/macro/mall/MallConfigApplicationTests.java new file mode 100644 index 0000000..ca7dcf2 --- /dev/null +++ b/mall-config/src/test/java/com/macro/mall/MallConfigApplicationTests.java @@ -0,0 +1,16 @@ +package com.macro.mall; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class MallConfigApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/mall-demo/pom.xml b/mall-demo/pom.xml index d3f8042..0436244 100644 --- a/mall-demo/pom.xml +++ b/mall-demo/pom.xml @@ -35,10 +35,8 @@ spring-cloud-starter-openfeign - org.springframework.security - spring-security-core - 5.1.6.RELEASE - compile + org.springframework.cloud + spring-cloud-starter-config diff --git a/mall-demo/src/main/resources/application.yml b/mall-demo/src/main/resources/application.yml index e339027..0a122b5 100644 --- a/mall-demo/src/main/resources/application.yml +++ b/mall-demo/src/main/resources/application.yml @@ -1,8 +1,6 @@ server: port: 8082 spring: - application: - name: mall-demo datasource: url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai username: root @@ -11,20 +9,6 @@ mybatis: mapper-locations: - classpath:mapper/*.xml - classpath*:com/**/mapper/*.xml -logging: - level: - root: info #日志配置DEBUG,INFO,WARN,ERROR - com.macro.mall: debug - com.macro.mall.demo.service.FeignAdminService: debug -host: - mall: - admin: http://mall-admin -eureka: - client: - register-with-eureka: true - fetch-registry: true - service-url: - defaultZone: http://localhost:8001/eureka/ management: #开启SpringBoot Admin的监控 endpoints: web: @@ -33,3 +17,6 @@ management: #开启SpringBoot Admin的监控 endpoint: health: show-details: always +host: + mall: + admin: http://mall-admin diff --git a/mall-demo/src/main/resources/bootstrap-dev.yml b/mall-demo/src/main/resources/bootstrap-dev.yml new file mode 100644 index 0000000..e36963e --- /dev/null +++ b/mall-demo/src/main/resources/bootstrap-dev.yml @@ -0,0 +1,13 @@ +spring: + cloud: + config: + profile: dev #启用环境名称 + label: master #分支名称 + name: demo #配置文件名称 + discovery: + enabled: true + service-id: mall-config +eureka: + client: + service-url: + defaultZone: http://localhost:8001/eureka/ \ No newline at end of file diff --git a/mall-demo/src/main/resources/bootstrap-prod.yml b/mall-demo/src/main/resources/bootstrap-prod.yml new file mode 100644 index 0000000..a8a2ef5 --- /dev/null +++ b/mall-demo/src/main/resources/bootstrap-prod.yml @@ -0,0 +1,13 @@ +spring: + cloud: + config: + profile: prod #启用环境名称 + label: master #分支名称 + name: demo #配置文件名称 + discovery: + enabled: true + service-id: mall-config +eureka: + client: + service-url: + defaultZone: http://localhost:8001/eureka/ \ No newline at end of file diff --git a/mall-demo/src/main/resources/bootstrap.yml b/mall-demo/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..3821157 --- /dev/null +++ b/mall-demo/src/main/resources/bootstrap.yml @@ -0,0 +1,5 @@ +spring: + profiles: + active: dev + application: + name: mall-demo \ No newline at end of file diff --git a/mall-portal/pom.xml b/mall-portal/pom.xml index e0d9e30..8ebe985 100644 --- a/mall-portal/pom.xml +++ b/mall-portal/pom.xml @@ -52,6 +52,10 @@ org.springframework.cloud spring-cloud-starter-netflix-eureka-client + + org.springframework.cloud + spring-cloud-starter-config + diff --git a/mall-portal/src/main/java/com/macro/mall/portal/config/TomcatConfig.java b/mall-portal/src/main/java/com/macro/mall/portal/config/TomcatConfig.java deleted file mode 100644 index b462be0..0000000 --- a/mall-portal/src/main/java/com/macro/mall/portal/config/TomcatConfig.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.macro.mall.portal.config; - -import org.apache.catalina.connector.Connector; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; - -/** - * tomcat相关配置 - * Created by macro on 2018/8/7. - */ -@Profile("https") -@Configuration -public class TomcatConfig { - @Value("${http.port}") - private Integer port; - @Bean - public TomcatServletWebServerFactory servletContainer() { - TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory(); - tomcat.addAdditionalTomcatConnectors(createStandardConnector()); // 添加http - return tomcat; - } - - //配置http - private Connector createStandardConnector() { - Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); - connector.setPort(port); - return connector; - } -} diff --git a/mall-portal/src/main/resources/application-dev.yml b/mall-portal/src/main/resources/application-dev.yml deleted file mode 100644 index 24021e7..0000000 --- a/mall-portal/src/main/resources/application-dev.yml +++ /dev/null @@ -1,59 +0,0 @@ -spring: - datasource: - url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai - username: root - password: root - druid: - initial-size: 5 #连接池初始化大小 - min-idle: 10 #最小空闲连接数 - max-active: 20 #最大连接数 - web-stat-filter: - exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" #不统计这些请求数据 - stat-view-servlet: #访问监控网页的登录用户名和密码 - login-username: druid - login-password: druid - data: - mongodb: - host: localhost - port: 27017 - database: mall-port - redis: - host: localhost # Redis服务器地址 - database: 0 # Redis数据库索引(默认为0) - port: 6379 # Redis服务器连接端口 - password: 123456 # Redis服务器连接密码(默认为空) - jedis: - pool: - max-active: 8 # 连接池最大连接数(使用负值表示没有限制) - max-wait: -1ms # 连接池最大阻塞等待时间(使用负值表示没有限制) - max-idle: 8 # 连接池中的最大空闲连接 - min-idle: 0 # 连接池中的最小空闲连接 - timeout: 3000ms # 连接超时时间(毫秒) - rabbitmq: - host: localhost - port: 5672 - virtual-host: /mall - username: mall - password: mall - publisher-confirms: true #如果对异步消息需要回调必须设置为true -# 日志配置 -logging: - level: - org.springframework.data.mongodb.core: debug - com.macro.mall.mapper: debug - com.macro.mall.portal.dao: debug -eureka: - client: - register-with-eureka: true - fetch-registry: true - service-url: - defaultZone: http://localhost:8001/eureka/ -management: #开启SpringBoot Admin的监控 - endpoints: - web: - exposure: - include: '*' - endpoint: - health: - show-details: always - diff --git a/mall-portal/src/main/resources/application-https.yml b/mall-portal/src/main/resources/application-https.yml deleted file mode 100644 index f4670f8..0000000 --- a/mall-portal/src/main/resources/application-https.yml +++ /dev/null @@ -1,52 +0,0 @@ -server: - port: 8443 #https环境会开启https - ssl: - key-store: keystore.p12 - key-alias: tomcat - key-store-password: 123456 - key-store-type: PKCS12 -spring: - datasource: - url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai - username: root - password: root - druid: - initial-size: 5 #连接池初始化大小 - min-idle: 10 #最小空闲连接数 - max-active: 20 #最大连接数 - web-stat-filter: - exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" #不统计这些请求数据 - stat-view-servlet: #访问监控网页的登录用户名和密码 - login-username: druid - login-password: druid - data: - mongodb: - host: localhost - port: 27017 - database: mall-port - redis: - host: localhost # Redis服务器地址 - database: 0 # Redis数据库索引(默认为0) - port: 6379 # Redis服务器连接端口 - password: # Redis服务器连接密码(默认为空) - jedis: - pool: - max-active: 8 # 连接池最大连接数(使用负值表示没有限制) - max-wait: -1ms # 连接池最大阻塞等待时间(使用负值表示没有限制) - max-idle: 8 # 连接池中的最大空闲连接 - min-idle: 0 # 连接池中的最小空闲连接 - timeout: 3000ms # 连接超时时间(毫秒) - rabbitmq: - host: localhost - port: 5672 - virtual-host: /mall - username: mall - password: mall - publisher-confirms: true #如果对异步消息需要回调必须设置为true -# 日志配置 -logging: - level: - org.springframework.data.mongodb.core: debug - com.macro.mall.mapper: debug - com.macro.mall.portal.dao: debug - diff --git a/mall-portal/src/main/resources/application-prod.yml b/mall-portal/src/main/resources/application-prod.yml deleted file mode 100644 index 5b86962..0000000 --- a/mall-portal/src/main/resources/application-prod.yml +++ /dev/null @@ -1,42 +0,0 @@ -spring: - datasource: - url: jdbc:mysql://db:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai - username: reader - password: 123456 - druid: - initial-size: 5 #连接池初始化大小 - min-idle: 10 #最小空闲连接数 - max-active: 20 #最大连接数 - web-stat-filter: - exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" #不统计这些请求数据 - stat-view-servlet: #访问监控网页的登录用户名和密码 - login-username: druid - login-password: druid - data: - mongodb: - host: mongo - port: 27017 - database: mall-port - redis: - host: redis # Redis服务器地址 - database: 0 # Redis数据库索引(默认为0) - port: 6379 # Redis服务器连接端口 - password: # Redis服务器连接密码(默认为空) - jedis: - pool: - max-active: 8 # 连接池最大连接数(使用负值表示没有限制) - max-wait: -1ms # 连接池最大阻塞等待时间(使用负值表示没有限制) - max-idle: 8 # 连接池中的最大空闲连接 - min-idle: 0 # 连接池中的最小空闲连接 - timeout: 0ms # 连接超时时间(毫秒) - rabbitmq: - host: rabbit - port: 5672 - virtual-host: /mall - username: mall - password: mall - publisher-confirms: true #如果对异步消息需要回调必须设置为true -# 日志配置 -logging: - path: /var/logs - diff --git a/mall-portal/src/main/resources/application.yml b/mall-portal/src/main/resources/application.yml index 9911eef..e2e060e 100644 --- a/mall-portal/src/main/resources/application.yml +++ b/mall-portal/src/main/resources/application.yml @@ -1,17 +1,56 @@ -spring: - profiles: - active: dev #默认为开发环境 - application: - name: mall-portal server: port: 8085 +spring: + datasource: + url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai + username: root + password: root + druid: + initial-size: 5 #连接池初始化大小 + min-idle: 10 #最小空闲连接数 + max-active: 20 #最大连接数 + web-stat-filter: + exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" #不统计这些请求数据 + stat-view-servlet: #访问监控网页的登录用户名和密码 + login-username: druid + login-password: druid + data: + mongodb: + host: localhost + port: 27017 + database: mall-port + redis: + host: localhost # Redis服务器地址 + database: 0 # Redis数据库索引(默认为0) + port: 6379 # Redis服务器连接端口 + password: 123456 # Redis服务器连接密码(默认为空) + jedis: + pool: + max-active: 8 # 连接池最大连接数(使用负值表示没有限制) + max-wait: -1ms # 连接池最大阻塞等待时间(使用负值表示没有限制) + max-idle: 8 # 连接池中的最大空闲连接 + min-idle: 0 # 连接池中的最小空闲连接 + timeout: 3000ms # 连接超时时间(毫秒) + rabbitmq: + host: localhost + port: 5672 + virtual-host: /mall + username: mall + password: mall + publisher-confirms: true #如果对异步消息需要回调必须设置为true mybatis: mapper-locations: - classpath:dao/*.xml - classpath*:com/**/mapper/*.xml -http: - port: 8085 # http服务端口 -# 自定义redis key +management: #开启SpringBoot Admin的监控 + endpoints: + web: + exposure: + include: '*' + endpoint: + health: + show-details: always +# 自定义redis键值 redis: key: prefix: @@ -19,7 +58,7 @@ redis: orderId: "portal:orderId:" expire: authCode: 90 # 验证码超期时间 -# 消息队列定义 +# 自定义消息队列名称 rabbitmq: queue: name: diff --git a/mall-portal/src/main/resources/bootstrap-dev.yml b/mall-portal/src/main/resources/bootstrap-dev.yml new file mode 100644 index 0000000..6f75d09 --- /dev/null +++ b/mall-portal/src/main/resources/bootstrap-dev.yml @@ -0,0 +1,13 @@ +spring: + cloud: + config: + profile: dev #启用环境名称 + label: master #分支名称 + name: portal #配置文件名称 + discovery: + enabled: true + service-id: mall-config +eureka: + client: + service-url: + defaultZone: http://localhost:8001/eureka/ \ No newline at end of file diff --git a/mall-portal/src/main/resources/bootstrap-prod.yml b/mall-portal/src/main/resources/bootstrap-prod.yml new file mode 100644 index 0000000..2e02087 --- /dev/null +++ b/mall-portal/src/main/resources/bootstrap-prod.yml @@ -0,0 +1,13 @@ +spring: + cloud: + config: + profile: prod #启用环境名称 + label: master #分支名称 + name: portal #配置文件名称 + discovery: + enabled: true + service-id: mall-config +eureka: + client: + service-url: + defaultZone: http://localhost:8001/eureka/ \ No newline at end of file diff --git a/mall-portal/src/main/resources/bootstrap.yml b/mall-portal/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..95af8d6 --- /dev/null +++ b/mall-portal/src/main/resources/bootstrap.yml @@ -0,0 +1,5 @@ +spring: + profiles: + active: dev + application: + name: mall-portal \ No newline at end of file diff --git a/mall-search/pom.xml b/mall-search/pom.xml index f947093..8c354c2 100644 --- a/mall-search/pom.xml +++ b/mall-search/pom.xml @@ -37,6 +37,10 @@ org.springframework.cloud spring-cloud-starter-netflix-eureka-client + + org.springframework.cloud + spring-cloud-starter-config + diff --git a/mall-search/src/main/resources/application-dev.yml b/mall-search/src/main/resources/application-dev.yml deleted file mode 100644 index 29e2a50..0000000 --- a/mall-search/src/main/resources/application-dev.yml +++ /dev/null @@ -1,33 +0,0 @@ -spring: - datasource: - url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai - username: root - password: root - druid: - initial-size: 5 #连接池初始化大小 - min-idle: 10 #最小空闲连接数 - max-active: 20 #最大连接数 - web-stat-filter: - exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" #不统计这些请求数据 - stat-view-servlet: #访问监控网页的登录用户名和密码 - login-username: druid - login-password: druid - data: - elasticsearch: - repositories: - enabled: true - cluster-nodes: 127.0.0.1:9300 -eureka: - client: - register-with-eureka: true - fetch-registry: true - service-url: - defaultZone: http://localhost:8001/eureka/ -management: #开启SpringBoot Admin的监控 - endpoints: - web: - exposure: - include: '*' - endpoint: - health: - show-details: always \ No newline at end of file diff --git a/mall-search/src/main/resources/application-prod.yml b/mall-search/src/main/resources/application-prod.yml deleted file mode 100644 index 7d40256..0000000 --- a/mall-search/src/main/resources/application-prod.yml +++ /dev/null @@ -1,23 +0,0 @@ -spring: - datasource: - url: jdbc:mysql://db:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai - username: reader - password: 123456 - druid: - initial-size: 5 #连接池初始化大小 - min-idle: 10 #最小空闲连接数 - max-active: 20 #最大连接数 - web-stat-filter: - exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" #不统计这些请求数据 - stat-view-servlet: #访问监控网页的登录用户名和密码 - login-username: druid - login-password: druid - - data: - elasticsearch: - repositories: - enabled: true - cluster-nodes: es:9300 - -logging: - path: /var/logs #配置日志生成路径 diff --git a/mall-search/src/main/resources/application.yml b/mall-search/src/main/resources/application.yml index e5ceb1b..e732a8d 100644 --- a/mall-search/src/main/resources/application.yml +++ b/mall-search/src/main/resources/application.yml @@ -1,21 +1,37 @@ -spring: - profiles: - active: dev #默认为开发环境 - application: - name: mall-search - server: port: 8081 - +spring: + datasource: + url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai + username: root + password: root + druid: + initial-size: 5 #连接池初始化大小 + min-idle: 10 #最小空闲连接数 + max-active: 20 #最大连接数 + web-stat-filter: + exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" #不统计这些请求数据 + stat-view-servlet: #访问监控网页的登录用户名和密码 + login-username: druid + login-password: druid + data: + elasticsearch: + repositories: + enabled: true + cluster-nodes: 127.0.0.1:9300 + cluster-name: elasticsearch mybatis: mapper-locations: - classpath:dao/*.xml - classpath*:com/**/mapper/*.xml - -logging: - level: - root: info - com.macro.mall: debug +management: #开启SpringBoot Admin的监控 + endpoints: + web: + exposure: + include: '*' + endpoint: + health: + show-details: always diff --git a/mall-search/src/main/resources/bootstrap-dev.yml b/mall-search/src/main/resources/bootstrap-dev.yml new file mode 100644 index 0000000..aa84ef6 --- /dev/null +++ b/mall-search/src/main/resources/bootstrap-dev.yml @@ -0,0 +1,13 @@ +spring: + cloud: + config: + profile: dev #启用环境名称 + label: master #分支名称 + name: search #配置文件名称 + discovery: + enabled: true + service-id: mall-config +eureka: + client: + service-url: + defaultZone: http://localhost:8001/eureka/ \ No newline at end of file diff --git a/mall-search/src/main/resources/bootstrap-prod.yml b/mall-search/src/main/resources/bootstrap-prod.yml new file mode 100644 index 0000000..d917ec3 --- /dev/null +++ b/mall-search/src/main/resources/bootstrap-prod.yml @@ -0,0 +1,13 @@ +spring: + cloud: + config: + profile: prod #启用环境名称 + label: master #分支名称 + name: search #配置文件名称 + discovery: + enabled: true + service-id: mall-config +eureka: + client: + service-url: + defaultZone: http://localhost:8001/eureka/ \ No newline at end of file diff --git a/mall-search/src/main/resources/bootstrap.yml b/mall-search/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..5bc8a45 --- /dev/null +++ b/mall-search/src/main/resources/bootstrap.yml @@ -0,0 +1,5 @@ +spring: + profiles: + active: dev + application: + name: mall-search \ No newline at end of file diff --git a/pom.xml b/pom.xml index fa6062b..8800da5 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,7 @@ mall-registry mall-monitor mall-gateway + mall-config