zoukankan      html  css  js  c++  java
  • SpringMVC+SpringBoot使用Maven进行多环境打包

    有道云笔记地址:

      https://note.youdao.com/ynoteshare1/index.html?id=b3f80dcf489aaf72bdcfbec2762726a4&type=note

    SpringMVC:
     
    1. 通过maven的filter实现动态打包
     
    2. 在resources目录下建一个filter文件夹用于存放多环境配置的properties文件,比如:
      name-dev.properties,name-test.properties,name-product.properties
     
    3. 修改pom.xml
      <build>
        <!-- 通过profile决定env, 根据env来试用不同的过滤文件来处理resources中的properties文件 -->
        <!--获得过滤使用的源文件,即有实际数据的地方-->
        <filters>
          <filter>src/main/resources/filter/name-${env}.properties</filter>
        </filters>
     
        <resources>
          <resource>
            <targetPath>${project.build.directory}/classes</targetPath>
            <directory>src/main/resources</directory>
            <!--是否使用过滤器-->
            <filtering>true</filtering>
            <includes>
              <include>**/*.xml</include>
              <include>**/*.properties</include>
            </includes>
          </resource>
        </resources>
      </build>
     
      <!-- 打包的不同profile -->
      <profiles>
        <!-- 开发 -->
        <profile>
          <id>dev</id>
          <properties>
            <env>dev</env>
          </properties>
          <!--默认激活-->
          <activation>
            <activeByDefault>true</activeByDefault>
          </activation>
        </profile>
        <!-- 测试 -->
        <profile>
          <id>test</id>
          <properties>
            <env>test</env>
          </properties>
        </profile>
        <!-- 生产 -->
         <profile>
          <id>product</id>
          <properties>
            <env>product</env>
          </properties>
        </profile>
      </profiles>
     
    4. 在IDEA中选择需要的文件进行打包
     
    SpringBoot:
     
    1. 通过修改application.yml中的配置为动态值来实现
    spring:
    # 读取maven的profile
    profiles:
    active: @active@
     
    2. 配置文件结构如下:
     
    3. 修改pom.xml
    如果未使用自定义的<parent>,则只需要配置以下内容
     
    <resource>
    <directory>src/main/resources</directory>
    <!--是否使用过滤器-->
    <filtering>true</filtering>
    </resource>
     
    <!-- 打包的不同profile -->
    <profiles>
    <!-- 开发 -->
    <profile>
    <id>dev</id>
    <properties>
    <active>dev</active>
    </properties>
    <!--默认激活-->
    <activation>
    <activeByDefault>true</activeByDefault>
    </activation>
    </profile>
    <!-- 测试 -->
    <profile>
    <id>test</id>
    <properties>
    <active>test</active>
    </properties>
    </profile>
    <!-- 阿里云测试 -->
    <profile>
    <id>test-aliyun</id>
    <properties>
    <active>test-aliyun</active>
    </properties>
    </profile>
    <!-- 生产 -->
    <profile>
    <id>product</id>
    <properties>
    <active>prod</active>
    </properties>
    <!--默认激活-->
    <!--<activation>-->
    <!--<activeByDefault>true</activeByDefault>-->
    <!--</activation>-->
    </profile>
    </profiles>
     
    4. 如果使用自定义的<parent>,额外添加如下配置
    <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>2.0.2.RELEASE</version>
    <configuration>
    <!-- 解决引用自定义parent后,找不到主清单的问题 -->
    <mainClass>${start-class}</mainClass>
    <layout>ZIP</layout>
    <outputDirectory>${project.basedir}/output</outputDirectory>
    </configuration>
    <!-- 解决引用自定义parent后,找不到主清单的问题 -->
    <executions>
    <execution>
    <goals>
    <goal>repackage</goal>
    </goals>
    </execution>
    </executions>
    </plugin>
     
    5. 在IDEA中选择需要的文件进行打包
     
  • 相关阅读:
    JVM(5)之 GC之标记
    JVM(4)之 使用MAT排查堆溢出
    JVM(3) 之 内存分配与回收策略
    JVM(2)之 JAVA堆
    JVM(1)之 JAVA栈
    MySQL查询时报错Illegal mix of collations
    struts2 基础学习
    python3.4 + pycharm安装与使用
    Pycharm激活
    IntelliJ IDEA 2018.2激活
  • 原文地址:https://www.cnblogs.com/weijs/p/11652348.html
Copyright © 2011-2022 走看看