zoukankan      html  css  js  c++  java
  • springboot 多环境配置及打包资源

    1. 配置多环境
    	<!-- 多环境配置方案  命令dev包 : mvn -U clean compile package -P dev-->
    	<profiles>
    		<profile>
    			<id>dev</id>
    			<properties>
    				<profileActive>dev</profileActive>
    				<maven.test.skip>true</maven.test.skip>
    				<scope.jar>compile</scope.jar>
    			</properties>
    			<activation>
    				<activeByDefault>true</activeByDefault> <!-- 设置默认的打包环境 -->
    			</activation>
    		</profile>
    		<profile>
    			<id>prod</id>
    			<properties>
    				<profileActive>prod</profileActive> <!-- 自定义变量,在pom和yaml中引用 -->
    				<maven.test.skip>true</maven.test.skip>
    			</properties>
    		</profile>
    	</profiles>
    
    1. 把需要打包的资源添加进来,不用环境的配置文件放在 env/${profileActive}下,至于加载配置文件,请看我另外一篇文章springboot自定义yaml配置文件
    	<build>
    		<finalName>${project.artifactId}-${profileActive}-${project.version}</finalName>
    		<resources>
    			<resource>
    				<directory>src/main/resources</directory>
    				<filtering>true</filtering>
    				<includes>
    					<include>env/${profileActive}/**</include> <!-- 引用的是1中的多环境配置的自定义属性 -->
    					<include>statics/**</include>
    					<include>templates/**</include>
    					<include>*.xml</include>
    					<include>*.txt</include>
    					<include>application-${profileActive}.yml</include>
    					<include>application.yml</include>
    				</includes>
    			</resource>
    		</resources>
    		<plugins>
    			<plugin>
    				<groupId>org.springframework.boot</groupId>
    				<artifactId>spring-boot-maven-plugin</artifactId>
    				<version>2.3.4.RELEASE</version>
    			</plugin>
    		</plugins>
    	</build>
    
    1. 在application.yaml文件中引用profileActive属性,这样在打包的时候只需要执行 mvn -U clean compile package -P prod 就会自动把prod环境的资源都打进去了
    spring:
      # 环境 dev|test|prod
      profiles:
        active: @profileActive@
    
  • 相关阅读:
    zoj 3644 Kitty's Game
    Planets
    hdoj 2571 命运
    (理论篇)IOC概述和Unity的使用
    重温设计模式之单例模式
    重温设计模式之观察者
    重温设计模式之装饰者
    (理论篇)PetShop全概述
    (理论篇)petshop中缓存运用之我见
    (理论篇)cookie,session,viewstate,cache
  • 原文地址:https://www.cnblogs.com/patrick-king/p/14149793.html
Copyright © 2011-2022 走看看