一.如果配置文件为: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. 如何写Java文档注释(Java Doc Comments)

    本文翻译自How to Write Doc Comments for the Javadoc Tool,但是精简了一些私以为不重要的东西 本文不讨论如何使用javadoc工具自动生成文档的方法,而是主 ...

  2. [luoguP1056] 排座椅(sort + 模拟)

    传送门 nc题,一直sort就过了 代码 #include <cstdio> #include <iostream> #include <algorithm> #d ...

  3. Python模块基础

    概念: 在Python中,一个.py文件就称之为一个模块(Module) 好处: 1. 提高可维护性 2. 可重用 3. 避免函数名.变量名冲突. 每个模块有独立的命名空间,因此相同名字的函数和变量完 ...

  4. 学习日常笔记<day09>Http协议

    1 Http协议入门 1.1 什么是http协议 http协议: 对浏览器客户端 和  服务器端 之间数据传输的格式规范 1.2 查看http协议的工具 1)使用火狐的firebug插件(右键-> ...

  5. C#写的NoSQL开源项目/系统(系列)

    http://www.cnblogs.com/unruledboy/archive/2013/01/07/CSharpNoSQL.html 闲扯 好久没写开源项目了,也没写对新开源项目的介绍,今晚看了 ...

  6. IDM百度云使用

    2018-8-6 (idm百度云速度很慢) Tips:如果感觉图片较小,可以ctrl+鼠标滚轮放大网页 首先下载IDM绿色版. 解压后:右键以管理员权限运行进行绿化 最后,它会在所有支持的浏览器上安装 ...

  7. Java设计模式—单例设计模式(Singleton Pattern)全然解析

    转载请注明出处:http://blog.csdn.net/dmk877/article/details/50311791 相信大家都知道设计模式,听的最多的也应该是单例设计模式,这种模式也是在开发中用 ...

  8. 【Hibernate】Hibernate的多表查询

    在<[Hibernate]Hibernate的聚类查询.分组查询.排序与时间之差>(点击打开链接)一文中已经讲述过怎样利用HQL语句代替SQL语句.进行聚类查询.分组查询.排序与时间之差的 ...

  9. 让你完全理解base64是怎么回事

    HTTP将BASE64-编码用于基本认证和摘要认证,在几种HTTP扩展中也使用了该编码. Base-64编码保证了二进制数据的安全 Base-64编码可以将任意一组字节转换为较长的常见文本字符序列,从 ...

  10. 10.11无法打开Xcode6.4的解决方法

    前言 mac升级到10.11版本号并安装Xcode7.0Beta之后,Dock中的Xcode6.3图标上出现一个禁止符号,打开提示到App store更新最新版本号,更新到6.4之后问题依然,还是提示 ...