先看看 maven 定义 profile 的写法

	<!-- profiles -->
<profiles>
<profile>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<id>dev</id>
<properties>
<profile.env>dev</profile.env>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<profile.env>test</profile.env>
</properties>
</profile>
<profile>
<id>product</id>
<properties>
<profile.env>product</profile.env>
</properties>
</profile>
</profiles>

  

然后在 spring.yml 里面这个么写

但是 spring 在运行的时候 已经和maven 没有关系了 这时候 ${ 变量名的写法 } 已经不生效了

备注: 这里 ${ 变量名 } 是maven 引用 变量的 写法。

比如:

这里的  ${serverA.version}_${profile.env}    分别是引用自 前面配置文件 中定义的  maven 变量   ${serverA.version} 来自  <properties>    ${profile.env}  来自 profile

怎么才能让 spring一识别 maven的  表达式呢?我们知道 spring运行在maven 打包以后,所以 不能可能spring运行的时候还能读取到 maven的 变量,所以只能是在maven打包的时候替换文件。 这就是核心思想了。加上下面的代码就可以打包的时候替换了spring.yml 中 maven的 变量了 。

    <resources>
<resource>
<directory>src/main/resources/</directory>
<filtering>true</filtering>
</resource>
</resources>

  

  这个 代码 加在 <build> 里面就可以了

	<!-- 指定jdk 的版本 -->
<build>
<resources>
<resource>
<directory>src/main/resources/</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

  

上面 多了一个 修改  jdk  版本的 配置,我的另一篇 博客里面写了 修改 jdk 版本的  maven的  2 中配置方式。

如果需要零时切换  profile  可以在 jar 后面 更上  --spring.profiles.active=dev

java -jar aaa.jar  --spring.profiles.active=dev

在 eclipse 中   run  右键  运行配置中指定

spring 使用 maven profile的更多相关文章

  1. [Spring Boot 系列] 集成maven和Spring boot的profile功能

    由于项目的需要, 今天给spirng boot项目添加了profile功能.再网上搜索了一圈,也没有找到满意的参考资料,其实配置并不难,就是没有一个one stop(一站式)讲解的地方,所以有了写这篇 ...

  2. 集成maven和Spring boot的profile功能

    思路:maven支持profile功能,当使用maven profile打包时,可以打包指定目录和指定文件,且可以修改文件中的变量.spring boot也支持profile功能,只要在applica ...

  3. 集成maven和Spring boot的profile 专题

    maven中配置profile节点: <project> .... <profiles> <profile> <!-- 生产环境 --> <id& ...

  4. 004-集成maven和Spring boot的profile功能打包

    参考地址:https://blog.csdn.net/lihe2008125/article/details/50443491 一.主要目标 1.通过mvn在命令行中打包时,可以指定相应的profil ...

  5. [Spring Boot 系列] 集成maven和Spring boot的profile 专题

    maven中配置profile节点: <project> .... <profiles> <profile> <!-- 生产环境 --> <id& ...

  6. 集成maven和Spring boot的profile

    如果在配置中勾选了多套配置,则以pom.xml文件中 profiles中  配置 最后一个配置为准. maven中配置profile节点: <project> .... <profi ...

  7. Spring Boot Maven Plugin(二):run目标

    简介 Spring Boot Maven Plugin插件提供spring boot在maven中的支持.允许你打包可运行的jar包或war包. 插件提供了几个maven目标和Spring Boot ...

  8. maven profile实现多环境配置

    每次项目部署上线都需要手动去修改配置文件(比如数据库配置,或者一个自定义的配置)然后才能打包,很麻烦,网上找到 maven profile可以完成这个工作,记录如下: 环境:eclipse + spr ...

  9. Spring 快速开始 Profile 和 Bean

    和maven profile类似,Spring bean definition profile 有两个组件:声明和激活. [栗子:开发测试环境使用HyperSQL 生产环境使用JNDI上下文根据配置查 ...

随机推荐

  1. JS-图片控制-动画管理模块

    animateManage.js ;(function(window,document,undefined){ var _aniQueue = [], //动画队列 --- ani:动画,Queue: ...

  2. 网络SSID是什么意思

    ssid是网络的ID(名称).一般用在无线网络上.搜索无线网络名一般就是在搜索无线网络的ssid. SSID是Service Set Identifier的缩写,意思是:服务集标识.SSID技术可以将 ...

  3. OC NSNumber和NSValue和NSDate和NSData

    一 NSNumber // // main.m // 07-NSNumber // // Created by apple on 13-8-12. // Copyright (c) 2013年 itc ...

  4. 进程通信方式-管道pipe

    管道是两个进程间进行单向通信的机制.因为管道传递数据的单向性,管道又称之为半双工管道. 1.数据只能从一个进程流向另一个进程(其中一个写管道,另一个读管道):如果要进行全双工通信,需要建立两个管道. ...

  5. POJ 2499 A*求第K短路

    DES就是给你一个图.然后给你起点和终点.问你从起点到终点的第K短路. 第一次接触A*算法. 题目链接:Remmarguts' Date 转载:http://blog.csdn.net/mbxc816 ...

  6. zabbix的搭建与入门

    一,Zabbix架构 zabbix 是一个基于 WEB 界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案.zabbix 能监视各种网络参数,保证服务器系统的安全运营:并提供灵活的通知机制 ...

  7. python随机数,随机选择……random

    import random from random import random, uniform, randint, randrange, choice, sample, shuffle list = ...

  8. Final阶段第1周/共1周 Scrum立会报告+燃尽图 04

    作业要求[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2483] 版本控制:https://git.coding.net/liuyy08 ...

  9. 利用security.js实现RSA加密

    在通常的http协议的网站中直接提交数据可以通过信息抓取从而暴露提交者所提交的信息,特别是注册时的密码和登录时的密码容易被泄露. 那么怎么防止这种现象呢? 很多人会想到加密技术,对没错,本文所讲的就是 ...

  10. Redis 缓存服务器

    Redis 服务器 Remote Dictionay Server   Redis是一个key-value持久化产品,通常被称为数据结构服务器. Redis的key是string类型:value可以是 ...