瀏覽代碼

多环境及部署打包

lrf 7 月之前
父節點
當前提交
c4acd700da

+ 50 - 0
pom.xml

@@ -8,6 +8,26 @@
   <version>0.0.1-SNAPSHOT</version>
   <name>customer</name>
   <description>Demo project for Spring Boot</description>
+  <packaging>war</packaging>
+  <profiles>
+    <!-- 开发 -->
+    <profile>
+      <id>dev</id>
+      <activation>
+        <activeByDefault>true</activeByDefault>
+      </activation>
+      <properties>
+        <env>dev</env>
+      </properties>
+    </profile>
+    <profile>
+      <!-- 生产 -->
+      <id>prod</id>
+      <properties>
+        <env>prod</env>
+      </properties>
+    </profile>
+  </profiles>
   <properties>
     <java.version>1.8</java.version>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -18,6 +38,20 @@
     <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-web</artifactId>
+      <!-- 移除嵌入式tomcat插件 -->
+      <exclusions>
+        <exclusion>
+          <groupId>org.springframework.boot</groupId>
+          <artifactId>spring-boot-starter-tomcat</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+
+    <!-- tomcat范围改成provided,否则后面就会出问题,tomcat无法解析jsp -->
+    <dependency>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-starter-tomcat</artifactId>
+      <scope>provided</scope>
     </dependency>
     <dependency>
       <groupId>org.springframework.boot</groupId>
@@ -105,6 +139,22 @@
   </dependencyManagement>
 
   <build>
+    <resources>
+      <resource>
+        <directory>src/main/resources</directory>
+        <excludes>
+          <exclude>application-*.yml</exclude>
+        </excludes>
+      </resource>
+      <resource>
+        <directory>src/main/resources</directory>
+        <filtering>true</filtering>
+        <includes>
+          <include>application.yml</include>
+          <include>application-${env}*.yml</include>
+        </includes>
+      </resource>
+    </resources>
     <plugins>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>

+ 9 - 1
readme.md

@@ -20,4 +20,12 @@
 
   
 ## token及验证:
-  自定义拦截器,针对所有路由进行检查. 如果函数使用@PassToken注解,则会跳过检查,否则会检查是否有登录信息.
+  自定义拦截器,针对所有路由进行检查. 如果函数使用@PassToken注解,则会跳过检查,否则会检查是否有登录信息.
+
+## 打包:
+  mvn clean install -Pprod
+
+## 部署,打war包,修改tomcat做代理
+${tomcat}/conf/server.xml
+<Host>节点下添加
+<Context path="${routePath}" docBase="${war包位置}" reloadable="true"></Context> 

+ 11 - 0
src/main/java/com/free/StartApplication.java

@@ -0,0 +1,11 @@
+package com.free;
+
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
+
+public class StartApplication extends SpringBootServletInitializer {
+  @Override
+  protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
+    return builder.sources(Main.class);
+  }
+}

+ 1 - 0
src/main/java/com/free/controller/TestController.java

@@ -54,6 +54,7 @@ public class TestController {
    * 
    * @return
    */
+  @PassToken
   @GetMapping()
   public Object list() {
     List list = testService.list();

+ 78 - 0
src/main/resources/application-dev.yml

@@ -0,0 +1,78 @@
+server:
+  port: 4001
+  servlet:
+    context-path: /customer/api
+    register-default-servlet: true
+
+spring:
+  mvc:
+    pathmatch:
+      matching-strategy: ant_path_matcher
+  servlet:
+    multipart:
+      enabled: true
+      max-file-size: 100MB
+      max-request-size: 1000MB
+      location: D:/temp/customerUpload/
+  datasource:
+    driver-class-name: com.mysql.cj.jdbc.Driver
+    url: jdbc:mysql://192.168.1.153:3306/customer?serverTimezone=GMT%2B8
+    username: root
+    password: root
+  rabbitmq:
+    host: 192.168.1.153
+    port: 5672
+    username: free
+    password: free1977
+    virtual-host: customer
+    listener:
+      simple:
+        concurrency: 1
+        max-concurrency: 3
+        # 消费者预取1条数据到内存,默认为250条
+        prefetch: 1
+        # 确定机制
+        acknowledge-mode: manual
+  devtools:
+    restart:
+      enabled: true
+  autoconfigure:
+    exclude: org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
+  jackson:
+    date-format: yyyy-MM-dd HH:mm:ss
+    time-zone: GMT+8
+    #设置空如何序列化
+    default-property-inclusion: non_null
+    serialization:
+      WRITE_DATES_AS_TIMESTAMPS: false
+      #格式化输出
+      indent_output: true
+      #忽略无法转换的对象
+      fail_on_empty_beans: false
+    deserialization:
+      #允许对象忽略json中不存在的属性
+      fail_on_unknown_properties: false
+    parser:
+      #允许出现特殊字符和转义符
+      allow_unquoted_control_chars: true
+      #允许出现单引号
+      allow_single_quotes: true
+
+mybatis:
+  table:
+    auto: update
+  model:
+    pack: com.free.entity
+  database:
+    type: mysql
+
+mybatis-plus:
+  mapper-locations: classpath*:com/gitee/sunchenbin/mybatis/actable/mapping/*/*.xml
+  #  type-aliases-package: com.free.entity
+  configuration:
+    map-underscore-to-camel-case: false
+    call-setters-on-nulls: true
+    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+logging:
+  level:
+    Mapper: debug

+ 78 - 0
src/main/resources/application-prod.yml

@@ -0,0 +1,78 @@
+server:
+  port: 4001
+  servlet:
+    context-path: /customer/api
+    register-default-servlet: true
+
+spring:
+  mvc:
+    pathmatch:
+      matching-strategy: ant_path_matcher
+  servlet:
+    multipart:
+      enabled: true
+      max-file-size: 100MB
+      max-request-size: 1000MB
+      location: /home/upload
+  datasource:
+    driver-class-name: com.mysql.cj.jdbc.Driver
+    url: jdbc:mysql://127.0.0.1:3306/customer?serverTimezone=GMT%2B8
+    username: root
+    password: free1977
+  rabbitmq:
+    host: 127.0.0.1
+    port: 5672
+    username: free
+    password: free1977
+    virtual-host: customer
+    listener:
+      simple:
+        concurrency: 1
+        max-concurrency: 3
+        # 消费者预取1条数据到内存,默认为250条
+        prefetch: 1
+        # 确定机制
+        acknowledge-mode: manual
+  devtools:
+    restart:
+      enabled: true
+  autoconfigure:
+    exclude: org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
+  jackson:
+    date-format: yyyy-MM-dd HH:mm:ss
+    time-zone: GMT+8
+    #设置空如何序列化
+    default-property-inclusion: non_null
+    serialization:
+      WRITE_DATES_AS_TIMESTAMPS: false
+      #格式化输出
+      indent_output: true
+      #忽略无法转换的对象
+      fail_on_empty_beans: false
+    deserialization:
+      #允许对象忽略json中不存在的属性
+      fail_on_unknown_properties: false
+    parser:
+      #允许出现特殊字符和转义符
+      allow_unquoted_control_chars: true
+      #允许出现单引号
+      allow_single_quotes: true
+
+mybatis:
+  table:
+    auto: update
+  model:
+    pack: com.free.entity
+  database:
+    type: mysql
+
+mybatis-plus:
+  mapper-locations: classpath*:com/gitee/sunchenbin/mybatis/actable/mapping/*/*.xml
+  #  type-aliases-package: com.free.entity
+  configuration:
+    map-underscore-to-camel-case: false
+    call-setters-on-nulls: true
+    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+logging:
+  level:
+    Mapper: debug

+ 2 - 77
src/main/resources/application.yml

@@ -1,78 +1,3 @@
-server:
-  port: 4001
-  servlet:
-    context-path: /customer/api
-    register-default-servlet: true
-
 spring:
-  mvc:
-    pathmatch:
-      matching-strategy: ant_path_matcher
-  servlet:
-    multipart:
-      enabled: true
-      max-file-size: 100MB
-      max-request-size: 1000MB
-      location: D:/temp/customerUpload/
-  datasource:
-    driver-class-name: com.mysql.cj.jdbc.Driver
-    url: jdbc:mysql://192.168.1.153:3306/customer?serverTimezone=GMT%2B8
-    username: root
-    password: root
-  rabbitmq:
-    host: 192.168.1.153
-    port: 5672
-    username: free
-    password: free1977
-    virtual-host: customer
-    listener:
-      simple:
-        concurrency: 1
-        max-concurrency: 3
-        # 消费者预取1条数据到内存,默认为250条
-        prefetch: 1
-        # 确定机制
-        acknowledge-mode: manual
-  devtools:
-    restart:
-      enabled: true
-  autoconfigure:
-    exclude: org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
-  jackson:
-    date-format: yyyy-MM-dd HH:mm:ss
-    time-zone: GMT+8
-    #设置空如何序列化
-    default-property-inclusion: non_null
-    serialization:
-      WRITE_DATES_AS_TIMESTAMPS: false
-      #格式化输出
-      indent_output: true
-      #忽略无法转换的对象
-      fail_on_empty_beans: false
-    deserialization:
-      #允许对象忽略json中不存在的属性
-      fail_on_unknown_properties: false
-    parser:
-      #允许出现特殊字符和转义符
-      allow_unquoted_control_chars: true
-      #允许出现单引号
-      allow_single_quotes: true
-
-mybatis:
-  table:
-    auto: update
-  model:
-    pack: com.free.entity
-  database:
-    type: mysql
-
-mybatis-plus:
-  mapper-locations: classpath*:com/gitee/sunchenbin/mybatis/actable/mapping/*/*.xml
-  #  type-aliases-package: com.free.entity
-  configuration:
-    map-underscore-to-camel-case: false
-    call-setters-on-nulls: true
-    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
-logging:
-  level:
-    Mapper: debug
+  profiles:
+    active: @env@