首先,你不需要使用个人资料。资源
db.properties是测试资源,因此应位于
src/test/resources而不是之下
src/main/resources。使用配置文件会使你的构建复杂化,你只能将它们作为最后的条件。
你遇到此问题的原因是Spring Boot将令牌过滤器重新定义为@而不是
default ${*}。从文档:如果你是从
spring-boot-starter-parentPOM 继承,则将的默认过滤器令牌
maven-resources-plugins从更改
${*}为@(即
@maven.token@而不是
${maven.token}),以防止与Spring样式的占位符冲突。如果application.properties直接启用了Maven过滤,则可能还需要更改默认过滤器令牌以使用其他定界符。
这意味着你应该改为:
jdbc.url= @db.jdbcUrl@jdbc.username= @db.jdbcUn@jdbc.password= @db.jdbcPw@
用于
db.properties文件。
然后,你需要删除自己的
<resources>部分,并将其替换为:
<testResources> <testResource> <directory>src/test/resources</directory> <filtering>true</filtering> <includes> <include>db.properties</include> </includes> </testResource></testResources>



