集成maven和Spring boot的profile功能

思路:maven支持profile功能,当使用maven profile打包时,可以打包指定目录和指定文件,且可以修改文件中的变量。spring boot也支持profile功能,只要在application.properties文件中指定spring.profiles.active=xxx 即可,其中xxx是一个变量,当maven打包时,修改这个变量即可。

1。配置maven 的profile

    <!-- 不同环境查找不同配置文件 -->
    <profiles>
        <profile>
            <id>dev</id>
            <properties>
                <profiles.active>dev</profiles.active>
                <maven.test.skip>true</maven.test.skip>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>sit</id>
            <properties>
                <profiles.active>sit</profiles.active>
                <maven.test.skip>true</maven.test.skip>
            </properties>
        </profile>
        <profile>
            <id>prd1</id>
            <properties>
                <profiles.active>prd1</profiles.active>
                <maven.test.skip>true</maven.test.skip>
                <scope.jar>provided</scope.jar>
            </properties>
        </profile>
        <profile>
            <id>prd2</id>
            <properties>
                <profiles.active>prd2</profiles.active>
                <maven.test.skip>true</maven.test.skip>
                <scope.jar>provided</scope.jar>
            </properties>
        </profile>
    </profiles>

其中profiles.active是我们定义的一个变量,可通过mvn命令指定,别人也能访问

在build中配置可修改可访问资源文件

        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <excludes>
                    <exclude>application-dev.properties</exclude>
                    <exclude>application-sit.properties</exclude>
                    <exclude>application-prd1.properties</exclude>
                    <exclude>application-prd2.properties</exclude>
                </excludes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>application-${profiles.active}.properties</include>
                    <include>application.properties</include>
                </includes>
            </resource>
        </resources>

其中  ${profiles.active}是上面profile中指定的变量

2.配置springboot的profile

  这是通过spring.profiles.active指定

  在application.properties中指定[email protected]@,即可这样就将maven与springboot的profile结合了

3.打包命令:mvn clean package -Dmaven.test.skip=true -P prod -e

原文地址:https://www.cnblogs.com/xiaoping1993/p/8183206.html

时间: 2024-08-04 06:17:30

集成maven和Spring boot的profile功能的相关文章

集成maven和Spring boot的profile 专题

maven中配置profile节点: <project> .... <profiles> <profile> <!-- 生产环境 --> <id>prod</id> <properties> <profiles.active>prod</profiles.active> </properties> </profile> <profile> <!-- 本地开发

在eclipse中安装maven和spring boot

在eclipse中安装maven和spring boot 1.打开help->install new software 2.点Add,Name(maven),Location(http://download.eclipse.org/technology/m2e/releases),OK,select然后next到安装中,等待安装完成. 3.新建maven项目 File->New->Project, 选择Maven Project next到 输入artifact id(项目名).grou

Maven 搭建spring boot多模块项目

Maven 搭建spring boot多模块项目 备注:所有项目都在idea中创建 1.idea创建maven项目 1-1: 删除src,target目录,只保留pom.xml 1-2: 根目录pom.xml可被子模块继承,因此项目只是demo,未考虑太多性能问题,所以将诸多依赖 都写在根级`pom.xml`,子模块只需继承就可以使用. 1-3: 根级pom.xml文件在附录1 1-4: 依赖模块 mybatis spring-boot相关模块 2.创建子模块(module) 2-1: file

Eeclipse集成Maven搭建Spring MVC

一.下载Maven 1.下载地址:https://maven.apache.org/ 2.将下载的zip包解压到指定目录下,如:E:\Tools\apache-maven-3.3.3 3.配置maven环境变量,新增环境变量 M2_HOME:E:\Tools\apache-maven-3.3.3,然后在环境变量的值后新增%M2_HOME%\bin 4.win+R,输入cmd启动dos命令行,输入mvn -version,出现如下图,即安装完成. 二.Eclipse集成Maven 1.如果你下载了

spring boot使用profile来区分正式环境配置文件与测试环境配置文件

转载请在页首注明作者与出处 一:前言 经常在开发的时候,项目中的配置文件,在个人开发的时候有一套配置文件,在测试环境有一套配置文件,在正式环境有一套配置文件,这个时候如果配置文件复杂,需要改的东西就特别多,而且由于迭代过程中,需要经常切换,难免发生问题. 二:SpringBoot的解决方式 其实准备的说应该说是spring的解决方式,因为spring boot中的这些也都是基于spring中的功能,当然spring boot肯定是要简单的多的. 2.1:准备多份配置文件 先准备两个文件放在src

Spring Mvc和Spring Boot读取Profile方式

spring boot java代码中获取spring.profiles.active - u013042707的专栏 - CSDN博客https://blog.csdn.net/u013042707/article/details/80632057 在Java类中取web.xml中配置的profile - mlz_2的专栏 - CSDN博客https://blog.csdn.net/mlz_2/article/details/80607821 原文地址:https://www.cnblogs.

基于Maven的Spring Boot项目配置

Maven项目都是基于pom.xml进行配置的. 这里我们参考Spring Boot的官方文档: https://docs.spring.io/spring-boot/docs/2.1.3.RELEASE/reference/htmlsingle/#getting-started-introducing-spring-boot 1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns=&qu

maven 打包 spring boot 生成docker 镜像

1.所使用材料 ,spring boot 项目 基于maven ,maven 工具, docker工具 ps:为啥使用 docker 公司微服务需要启动太多,有两个优点吧! 1.方便管理,2.减少服务占用内存量 2.上手 a.新建Dockerfile文件如下目录 b.Dockerfile文件内容 FROM openjdk:8-jdk-alpine VOLUME /tmp ARG JAR_FILE COPY ${JAR_FILE} app.jar ENTRYPOINT ["java",&

maven 构建spring boot + mysql 的基础项目

一.maven 依赖 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.1.RELEASE</version> <relativePath /> <!-- lookup parent from repository --&