抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

原因分析

在使用maven-resources-plugin插件时,发现${}做资源替换不生效。怎么设置都不生效。我的设置已经和文档上的一样了还是不生效。

今天终于在一篇博客的启发下,把${}改成@@,这样终于生效了。于是来查找不生效的原因。

原来插件依赖于<resource.delimiter>@</resource.delimiter>这个配置,而springboot把它给改成了@。

那换回来行不行呢?我还是建议不要换回来。因为springboot也需要这个${}占位符用于环境变量注入到实例Bean里。所以,${}要么给插件用,要么给springboot用。

解决

方法一:

在pom.xml里面添加如下内容

1
2
3
<properties>
<resource.delimiter>${}</resource.delimiter>
</properties>

方法二:

application.properties里面不用${},改成@

1
2
3
4
5
spring.datasource.url= @db.url@
spring.datasource.username=@db.username@
spring.datasource.password=@db.password@
spring.datasource.driver-class-name=@db.driverClassName@
spring.datasource.validationQuery=@db.validationQuery@

方法三:

pom.xml不继承spring-boot-starter-parent,dependency里面配置全部的依赖和版本号(继承了之后,很多依赖不用写version)

方法四:

1
2
3
4
5
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>

改成

1
2
3
4
5
6
7
8
9
10
11
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.9.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

参考来源

https://www.cnblogs.com/xiang--liu/p/11430219.html

评论