一.如果配置文件为:application.properties时

1.application.properties用于填些公共文件

   以下为不同环境的配置文件需要单独配置

    application-dev.properties

    application-prod.properties

    application-test.properties

 application.yml用于填些公共文件

   以下为不同环境的配置文件需要单独配置

    application-dev.yml

    application-prod.yml

    application-test.yml

2.application.properties内配置打包运行的环境

  spring.profiles.active=@profiles.active@

 application.ym配置文件中配置

  # 指定执行环境

  spring:

   profiles:

    active: @package.environment@

3.配置pom.xml打包配置

<!-- maven不同环境配置 -->
<profiles>
<!-- 开发环境 -->
  <profile>
    <id>test</id>
    <properties>
      <profiles.active>test</profiles.active>
    </properties>
    <activation>

      <!---指定默认激活->
      <activeByDefault>true</activeByDefault>
    </activation>
  </profile>
<!-- 演示环境 -->
  <profile>
    <id>dev</id>
    <properties>
      <profiles.active>dev</profiles.active>
    </properties>
  </profile>
<!-- 生产环境 -->
  <profile>
    <id>prod</id>
    <properties>
      <profiles.active>prod</profiles.active>
    </properties>
   </profile>
</profiles>

  

<build>
  <plugins>
    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
      <configuration>
        <fork>true</fork>
      </configuration>
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
      <configuration>
        <archive>
          <manifest>
            <mainClass>com.tkgm.api.StartAppApplication</mainClass>
            <addClasspath>true</addClasspath>
            <classpathPrefix>lib/</classpathPrefix>
          </manifest>
        </archive>
      </configuration>
    </plugin>
  </plugins>
<!-- resources是对配置文件资源的处理,使用见前言部分 -->
  <resources>
    <resource>
      <directory>src/main/java</directory>
      <includes>
        <include>**/*.class</include>
        <include>**/*.xml</include>
        <include>**/*.properties</include>
      </includes>
    </resource>
    <resource>
      <directory>src/main/resources</directory>
      <filtering>true</filtering>
      <excludes>
        <exclude>application-prod.properties</exclude>
        <exclude>application-dev.properties</exclude>
        <exclude>application-test.properties</exclude>
        <exclude>application.properties</exclude>
      </excludes>
    </resource>
    <resource>
      <directory>src/main/resources</directory>
<!--读取打包命令中指定的环境-->
      <filtering>true</filtering>
      <includes>
        <include>application.properties</include>
        <include>application-${profiles.active}.properties</include>
        <include>log4j2.properties</include>
        <include>jpush.properties</include>
        <include>apiurl.properties</include>
      </includes>
    </resource>
  </resources>
</build>

4.打包命令:打包查看jar打包结果

  mvn clean compile package -Dmaven.test.skip=true -Pdev

  

Spring boot 分环境部署的更多相关文章

  1. Spring Boot 多环境部署

    再简单的应用系统,通常都有两个环境——开发环境和线上环境.大型的企业应用还会有更多的环境,比如测试环境.准线上环境.演示环境等.应用的版本也可能对应了多个环境,比如1.0版本的演示环境.2.0版本的演 ...

  2. Spring Boot入门系列(十五)Spring Boot 开发环境热部署

    在实际的项目开发过中,当我们修改了某个java类文件时,需要手动重新编译.然后重新启动程序的,整个过程比较麻烦,特别是项目启动慢的时候,更是影响开发效率.其实Spring Boot的项目碰到这种情况, ...

  3. Spring boot+RabbitMQ环境

    Spring boot+RabbitMQ环境 消息队列在目前分布式系统下具备非常重要的地位,如下的场景是比较适合消息队列的: 跨系统的调用,异步性质的调用最佳. 高并发问题,利用队列串行特点. 订阅模 ...

  4. Spring Boot 多环境如何配置

    Spring Boot 开发环境.测试环境.预生产环境.生产环境多环境配置 通常一个公司的应程序可能在开发环境(dev).测试环境(test).生产环境(prod)中运行.那么是不是需要拷贝不同的安装 ...

  5. spring boot 开发环境搭建(Eclipse)

    Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...

  6. 从头开始搭建一个Spring boot+RabbitMQ环境

    *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...

  7. kotlin web开发教程【一】从零搭建kotlin与spring boot开发环境

    IDEA中文输入法的智能提示框不会跟随光标的问题 我用的开发工具是IDEA 这个版本的IDEA有一个问题: 就是中文输入法的智能提示框不会跟随光标 解决这个问题的办法很简单,只有在安装目录下把JRE文 ...

  8. Spring boot 应用打包部署

    1.Spring Boot内置web spring Boot 其默认是集成web容器的,启动方式由像普通Java程序一样,main函数入口启动.其内置Tomcat容器或Jetty容器,具体由配置来决定 ...

  9. Spring boot+ logback环境下,日志存放路径未定义的问题

    日志路径未定义 环境:Spring boot + logback 配置文件: <configuration> <springProfile name="dev"& ...

随机推荐

  1. 状态压缩DP总结

    POJ1185 炮兵部队问题: 在平原上才能放置炮兵,每个炮兵的上下左右2格之内都不能出现别的炮兵 可以考虑在当前行放置炮兵它的右侧和下侧绝对不会出现炮兵即可,左侧和上侧就能省去考虑 明显的状态压缩d ...

  2. idea使用之maven本地索引更新

    idea使用起来的确挺顺手的,但遇到一些问题时,直接百度很难有答案,只能自己慢慢摸索了. 今天在倒腾idea仓库索引的时候,就出事情啦. 先说idea更新本地仓库索引吧,打开settings--> ...

  3. 【周期性执行事件】MySQL事件(Event)&任务调度

    1.事件简介 事件(event)是MySQL在相应的时刻调用的过程式数据库对象.一个事件可调用一次,也可周期性的启动,它由一个特定的线程来管理的,也就是所谓的“事件调度器”. 事件和触发器类似,都是在 ...

  4. EditText实时监测内容

    editText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequ ...

  5. [bzoj2946][Poi2000]公共串_后缀数组_二分

    公共串 bzoj-2946 Poi-2000 题目大意:给定$n$个字符串,求他们的最长公共子串. 注释:$1\le n\le 5$,$1\le minlen<maxlen\le 2000$. ...

  6. 【天道酬勤】 腾讯、百度、网易游戏、华为Offer及笔经面经(转)

    应届生上泡了两年,一直都是下资料,下笔试题,面试题.一直都在感谢那些默默付出的人.写这个帖子花了我两 个夜晚的时间,不是为了炫耀,只是为了能给那些“迷惘”的学弟学妹,一点点建议而已.大家何必那么认真, ...

  7. Linux系统备份还原工具1(DD)(应用实例)

    DD使用教程:http://www.cnblogs.com/EasonJim/p/7442223.html 以下实例没经过大量测试,可能在一些机器上不会有效. 一般围绕以下几点进行设置: 1.dd完后 ...

  8. Maven公共仓库/镜像站收集及使用技巧

    查询: 1.http://search.maven.org/ 2.https://mvnrepository.com/ 3.https://maven-repository.com/ 4.(阿里云镜像 ...

  9. linux 下 打包 和解压缩

    01-.tar格式解包:[*******]$ tar xvf FileName.tar打包:[*******]$ tar cvf FileName.tar DirName(注:tar是打包,不是压缩! ...

  10. JSTL简单入门学习实例

    Maven依赖: <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</ ...