项目目录结构:

父pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.env</groupId>
<artifactId>test-environment</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>test-common</module>
<module>environment-demo</module>
</modules>
</project>

common pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>test-environment</artifactId>
<groupId>com.test.env</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>test-common</artifactId>
<version>1.0-SNAPSHOT</version>
<name>test-common</name>
</project>  

demo pom,filter区分环境:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>test-environment</artifactId>
<groupId>com.test.env</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<properties>
<java.version>1.8</java.version>
<project.version>1.0.0-RELEASE</project.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<springboot.version>1.5.20.RELEASE</springboot.version>
</properties> <artifactId>environment-demo</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${springboot.version}</version>
</dependency>
<dependency>
<groupId>com.test.env</groupId>
<artifactId>test-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies> <build>
<finalName>environment-demo</finalName>
<filters>
<filter>../filter/${env}/common.properties</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build> <profiles>
<profile>
<id>development</id>
<properties>
<env>dev</env>
<build.level>compile</build.level>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>beta</id>
<properties>
<env>beta</env>
<build.level>provided</build.level>
</properties>
</profile>
<profile>
<id>production</id>
<properties>
<env>production</env>
<build.level>provided</build.level>
</properties>
</profile>
</profiles> </project>

 spring-beans.xml:EnvironmentBean在common中

spring-confog.xml

springboot 通过BaseConfig导入spring配置

@SpringBootConfiguration
@ImportResource("classpath:spring/spring-config.xml")//多个bean的配置文件
public class BaseConfig {
}

springboot:

@SpringBootApplication
public class EnvironmentDemo implements CommandLineRunner{
@Autowired
EnvironmentBean config;
@Override
public void run(String... args) throws Exception {
System.out.println("config:"+config);
}
public static void main(String[] args) {
SpringApplication.run(EnvironmentDemo.class);
}
}

在demo 目录下区分打包beta,production环境:mvn clean package -P beta/production

spring-beans.xml 中env.name/desc的值会被替换为相应环境的值。

注意:如果是第一次打包可能会遇到Could not find artifact XXX,这是因为需要父工程打包到本地仓库,整个大项目一期build install就顺利通过,之后再子项目打包。

 

filter打包区分环境的更多相关文章

  1. webpack学习笔记--区分环境

    为什么需要区分环境 在开发网页的时候,一般都会有多套运行环境,例如: 在开发过程中方便开发调试的环境. 发布到线上给用户使用的运行环境. 这两套不同的环境虽然都是由同一套源代码编译而来,但是代码内容却 ...

  2. maven部署项目流程(区分环境)

    java项目区分环境打包部署到Linux 本文以一个简单的HelloWorld的项目为例,从pom.xml配置到打jar包,最后在linux上运行并验证来对maven部署的这套流程进行简单介绍. 为方 ...

  3. 通过maven profile 打包指定环境配置

    背景 最近换了个新公司接手了一个老项目,然后比较坑的是这个公司的项目都没有没有做多环境打包配置,每次发布一个环境都要手动的去修改配置文件.今天正好有空就来配置下. 解决这个问题的方式有很多,我这里挑选 ...

  4. vue分别打包测试环境和正式环境

    vue打包时使用不同的环境变量 需求 同一个项目通过打包使用不同的环境变量,目前的环境有三个: 一.本地------开发环境 二.线上------测试环境 三.线上------正式环境 我们都知道vu ...

  5. springboot打包不同环境配置与shell脚本部署

    本篇和大家分享的是springboot打包并结合shell脚本命令部署,重点在分享一个shell程序启动工具,希望能便利工作: profiles指定不同环境的配置 maven-assembly-plu ...

  6. maven 打包不同环境

    支持不同环境打包 1 pom添加如下配置: 1)添加指定打包id 区分各个环境 <profiles> <profile> <id>dev</id> &l ...

  7. 用 maven filter 管理不同环境的配置文件

    使用 maven profile 一个项目可以部署在不同的环境当中,maven 的 profile 针对不同的环境指定各自的编译方法.在 pom.xml 的 profile 中,可以根据不同的环境定制 ...

  8. ionic2使用cordova打包的环境搭建

    1.安装node.js(不用说了) 2.安装JDK(java的开发基础类库) 3.安装SDK(安卓开发集成包) 4.gradle( JAVA界的Weboack ,支撑app的编译,打包的流程) 5.安 ...

  9. spring-boot 速成(5) profile区分环境

    maven中的profile概念,在spring-boot中一样适合,只要约定以下几个规则即可: 一.不同环境的配置文件以"application-环境名.yml"命名 举个粟子: ...

随机推荐

  1. [008] - JavaSE面试题(八):集合

    第一期:Java面试 - 100题,梳理各大网站优秀面试题.大家可以跟着我一起来刷刷Java理论知识 [008] - JavaSE面试题(八):集合 第1问:说一下集合的体系? 单列集合: 双列集合: ...

  2. 替代Infinity绝佳的自主开发chrome插件

    最近闲来无事在好朋(da)友(shen)的帮助下开发一个chrome插件,目的是为了替换infinity主页插件, 当然在此也推荐一波infinity确实不错,界面和易用性都是非常好用的水准了. 主页 ...

  3. react应用(基于react脚手架)

    使用create-react-app创建react应用 react脚手架 1) xxx脚手架: 用来帮助程序员快速创建一个基于xxx库的模板项目 a. 包含了所有需要的配置 b. 指定好了所有的依赖 ...

  4. python的代码块和if条件表达式

    代码块和if条件表达式 代码块 什么是代码块 以冒号作为开始,用缩进来划分作用域. 在之后的学习当中,使用if条件语句.for.while循环语句.定义函数.定义类等诸多地方都会涵盖代码的概念. 什么 ...

  5. .net core工具组件系列之Redis—— 第一篇:Windows环境配置Redis(5.x以上版本)以及部署为Windows服务

    Cygwin工具编译Redis Redis6.x版本是未编译版本(官方很调皮,所以没办法,咱只好帮他们编译一下了),所以咱们先下载一个Cygwin,用它来对Redis进行编译. Cygwin下载地址: ...

  6. 前端基础js(四)

    一. js [1] html:用于显示页面 [2] css:用于描述页面的样式 [3] javaScript:用于描述页面的行为 二.js中三大部分内容 [1] 基本语法:函数.对象.事件类型(变量, ...

  7. git clone 中途停止不动

    参考链接1:https://blog.csdn.net/weixin_36965307/article/details/105046699 参考链接2:https://blog.csdn.net/le ...

  8. Python基础之用PyQt5写一个tabview

    前面学习了menu的画图,现在学习tabview的画图,关于怎么打开designer.exe部分就不详细介绍了. 第一步:拖动一个Tab Widget控件到窗口去. 将控件拖上去之后就是这个样子,默认 ...

  9. videojs文档翻译-EventTarget

    EventTarget new EventTarget()   EventTarget是一个可以与DOM EventTarget具有相同API的类. 它增加了包含冗长功能的缩写功能. 例如:on函数是 ...

  10. 使用C#winform编写渗透测试工具--SQL注入

    使用C#winform编写渗透测试工具--SQL注入 本篇文章主要介绍使用C#winform编写渗透测试工具,实现SQL注入的功能.使用python编写SQL注入脚本,基于get显错注入的方式进行数据 ...