Spring boot项目maven的profile多环境配置不自动替换变量的问题解决
 

在网上找了好久,配置都很简单,可是我的程序就是不能自动替换变量,最终单独测试,发现原来是引用spring boot parent的问题

引用一位博主的话"spring-boot为了保护application.yml和application.properties,修改了默认的占位符${...}为@...@,然后发现resources插件有一个配置项"

<useDefaultDelimiters>true</useDefaultDelimiters>

解决办法:

在build里面加plugin

  1. <pluginManagement>
  2. <plugins>
  3. <plugin>
  4. <artifactId>maven-resources-plugin</artifactId>
  5. <configuration>
  6. <encoding>utf-8</encoding>
  7. <useDefaultDelimiters>true</useDefaultDelimiters>
  8. </configuration>
  9. </plugin>
  10. </plugins>
  11. </pluginManagement> 

下面分享完整的配置,一共有两块,一块是profiles配置,一块是build

其中prifiles里面定义的 properties属性会替换.properties文件里面的变量

例如 application.properties里面有一个mapdb.path=${mapdb.path}

会被替换成正确的

  1. <build>
  2. <resources>
  3. <resource>
  4. <directory>src/main/resources</directory>
  5. <excludes>
  6. <exclude>dev/*</exclude>
  7. <exclude>prod/*</exclude>
  8. </excludes>
  9. </resource>
  10. <resource>
  11. <directory>src/main/resources/${profiles.active}</directory>
  12. <filtering>true</filtering>
  13. <includes>
  14. <include>**/*.properties</include>
  15. <include>**/*.xml</include>
  16. </includes>
  17. </resource>
  18. <resource>
  19. <directory>src/main/resources/</directory>
  20. <filtering>false</filtering>
  21. <includes>
  22. <include>**/*.xml</include>
  23. </includes>
  24. </resource>
  25. </resources>
  26. <pluginManagement>
  27. <plugins>
  28. <plugin>
  29. <artifactId>maven-resources-plugin</artifactId>
  30. <configuration>
  31. <encoding>utf-8</encoding>
  32. <useDefaultDelimiters>true</useDefaultDelimiters>
  33. </configuration>
  34. </plugin>
  35. </plugins>
  36. </pluginManagement>
  37. </build>

下面是profiles定义

  1. <profiles>
  2. <profile>
  3. <id>dev</id>
  4. <properties>
  5. <mapdb.path>${basedir}/mapdb</mapdb.path>
  6. <profiles.active>dev</profiles.active>
  7. </properties>
  8. <activation>
  9. <activeByDefault>true</activeByDefault>
  10. </activation>
  11. </profile>
  12. <profile>
  13. <id>production</id>
  14. <properties>
  15. <profiles.active>prod</profiles.active>
  16. </properties>
  17. </profile>
  18. </profiles>

Spring boot项目maven的profile多环境配置不自动替换变量的问题解决的更多相关文章

  1. Spring Boot项目使用maven-assembly-plugin根据不同环境打包成tar.gz或者zip

    spring-boot-assembly 在spring boot项目中使用maven profiles和maven assembly插件根据不同环境打包成tar.gz或者zip 将spring bo ...

  2. Spring Boot 项目 Maven 配置

    在配置基于Maven的Spring Boot项目的过程中,打包运行出现了一系列错误. 比如: mvn 中没有主清单属性.java.lang.NoClassDefFoundError: org/spri ...

  3. 【Spring Boot项目】Win7+JDK8+Tomcat8环境下的War包部署

    一.pom.xml及启动类修改 pom.xml Step1:指定打包类型 <!-- 打包类型 jar 或 war --> <packaging>war</packagin ...

  4. Spring Boot项目Maven Build报错的解决方法

    问题1, [ERROR]Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.21.0:test (defau ...

  5. spring boot项目maven打包可执行JAR

    在pom.xml中添加如下配置: <!-- 打包可执行jar包 --> <plugin> <groupId>org.springframework.boot< ...

  6. 使用 Docker 部署 Spring Boot 项目

    Docker 介绍 Docker 属于 Linux 容器的一种封装,提供简单易用的容器使用接口.它是目前最流行的 Linux 容器解决方案. Docker 将应用程序与该程序的依赖,打包在一个文件里面 ...

  7. Intellij IDEA Spring Boot 项目Debug模式启动缓慢问题

    问题 Intellij IDEA Spring Boot 项目Debug模式启动缓慢 环境 os: windows10 idea :2018.1 解决方法 去除所有断点就正常了,很诡异,原因未知.

  8. IDEA新建一个Spring Boot项目

    Maven构建项目模板 maven构建的是maven风格的纯净模板,要转变成spring boot项目需要自己添加依赖等配置. mvn archetype:generate: Maven插件原型是一个 ...

  9. Spring Boot 2.4版本前后的分组配置变化及对多环境配置结构的影响

    前几天在<Spring Boot 2.4 对多环境配置的支持更改>一文中,给大家讲解了Spring Boot 2.4版本对多环境配置的配置变化.除此之外,还有一些其他配置变化,所以今天我们 ...

随机推荐

  1. 基于Jenkins Pipeline的ASP.NET Core持续集成实践

    最近在公司实践持续集成,使用到了Jenkins的Pipeline来提高团队基于ASP.NET Core API服务的集成与部署效率,因此这里总结一下. 一.关于持续集成与Jenkins Pipelin ...

  2. [小技巧]EF Core中如何获取上下文中操作过的实体

    原文地址:https://www.cnblogs.com/lwqlun/p/10576443.html 作者:Lamond Lu 源代码:https://github.com/lamondlu/EFC ...

  3. js-刮刮卡效果,由jquery-eraser源码改的vue组件

    vue-eraser 一款用于vue刮刮卡的组件 github地址: vue-eraser npm地址: vue-eraser 在网上有看到过几个版本的组件,都有点问题 1.拉快了,就会断,连不起来( ...

  4. 解决ruby安装后无法添加淘宝gem源------------学习记录

    使用sass ,需要安装ruby,会建议移除gem源,添加淘宝的gem源,但是淘宝的镜像源已经停止维护啦!!用https://gems.ruby-china.com 代替即可. 操作如下: 1)删除原 ...

  5. Linux 桌面玩家指南:08. 使用 GCC 和 GNU Binutils 编写能在 x86 实模式运行的 16 位代码

    特别说明:要在我的随笔后写评论的小伙伴们请注意了,我的博客开启了 MathJax 数学公式支持,MathJax 使用$标记数学公式的开始和结束.如果某条评论中出现了两个$,MathJax 会将两个$之 ...

  6. SQL注入攻击的常见方式及测试方法

    本文主要针对SQL注入的含义.以及如何进行SQL注入和如何预防SQL注入让小伙伴有个了解.适用的人群主要是测试人员,了解如何进行SQL注入,可以帮助我们测试登录.发布等模块的SQL攻击漏洞,至于如何预 ...

  7. PHP获取远程http或ftp文件的md5值

    PHP获取本地文件的md5值: md5_file("/path/to/file.png"); PHP获取远程http文件的md5值: md5_file("https:// ...

  8. vue2.0 配置环境总结(都是泪啊)

    最近有点空闲时间,终于把一直想学的vue提上了日程,以下是收集的一些帮助入门的链接 1:https://vuefe.cn/v2/guide/ vue2.0中文官网 2:https://router.v ...

  9. Spring Cloud Eureka 常用配置详解,建议收藏!

    前几天,栈长分享了 <Spring Cloud Eureka 注册中心集群搭建,Greenwich 最新版!>,今天来分享下 Spring Cloud Eureka 常用的一些参数配置及说 ...

  10. pandas的apply操作

    pandas的apply操作类似于Scala的udf一样方便,假设存在如下dataframe: id_part pred pred_class v_id 0 d [0.722817, 0.650064 ...