springboot多profile环境maven配置
Posted Yuan.Net
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springboot多profile环境maven配置相关的知识,希望对你有一定的参考价值。
在application.properties 中加入
spring.profiles.active=dev
这里可以随便指定test[测试环境],prod[生产环境],dev[开发环境]
依次建立,当然里面需要分别有所属环境的配置
application-test.properties
application-prod.properties
application-dev.properties
直接上maven配置:
<?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.demo.flow</groupId> <artifactId>demo-flow-openapi</artifactId> <version>1.0.0</version> <packaging>jar</packaging> <name>demo-flow-openapi</name> <description>test project for flow-openapi</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>com.zaxxer</groupId> <artifactId>HikariCP</artifactId> </dependency> <dependency> <groupId>com.github.miemiedev</groupId> <artifactId>mybatis-paginator</artifactId> <version>RELEASE</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>RELEASE</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>RELEASE</version> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.1</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.1</version> </dependency> <dependency> <groupId>org.springframework.session</groupId> <artifactId>spring-session</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <profiles> <profile> <id>prod</id> <properties> <build.profile.id>prod</build.profile.id> </properties> </profile> <profile> <id>test</id> <properties> <build.profile.id>test</build.profile.id> </properties> </profile> <profile> <id>dev</id> <properties> <build.profile.id>dev</build.profile.id> </properties> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> </profiles> <build> <finalName>flow-openapi</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.7.0</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>utf8</encoding> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> <!--第一种profile方案[推荐第一种]--> <resources> <resource> <directory>src/main/resources</directory> <!--resource的filtering属性用来表示资源文件中的占位符是否需要被替换,true为需要替换--> <filtering>true</filtering> <!--引入资源文件信息--> <includes> <include>application.properties</include> <include>*.xml</include> <include>banner.txt</include> <include>application-${build.profile.id}.properties</include> </includes> </resource> </resources> <!--第二种profile方案-整理的网上其他方案--> <!--<resources>--> <!--<resource>--> <!--<directory>src/main/resources</directory>--> <!--<filtering>false</filtering>--> <!--<includes>--> <!--<include>**/*.xml</include>--> <!--</includes>--> <!--</resource>--> <!--<resource>--> <!--<directory>src/main/resources</directory>--> <!--<filtering>true</filtering>--> <!--<excludes>--> <!--<exclude>application-dev.properties</exclude>--> <!--<exclude>application-prod.properties</exclude>--> <!--<exclude>application-test.properties</exclude>--> <!--</excludes>--> <!--</resource>--> <!--<resource>--> <!--<filtering>true</filtering>--> <!--<directory>src/main/resources</directory>--> <!--<includes>--> <!--<include>application-${build.profile.id}.properties</include>--> <!--</includes>--> <!--</resource>--> <!--</resources>--> <!--第三种profile配置方案--> <!--<filters>--> <!--<filter>src/main/resources/application-${build.profile.id}.properties</filter>--> <!--</filters>--> <!--<resources>--> <!--<resource>--> <!--<filtering>true</filtering>--> <!--<directory>src/main/resources</directory>--> <!--</resource>--> <!--</resources>--> </build> </project>
相关扩展资料
https://yq.aliyun.com/articles/25408
http://blog.csdn.net/u011961421/article/details/78739805
http://blog.csdn.net/zxzzxzzxz123/article/details/70144397
以上是关于springboot多profile环境maven配置的主要内容,如果未能解决你的问题,请参考以下文章