我继承的Maven项目有一些JUnits中使用的资源文件。
这些文件在属性文件中被称为绝对路径。
我们假设 Maven 项目位于myproject
,其中主要pom.xml
居住。
A config.properties
文件有:
keystore.file=C:/Users/tom/myproject/web/src/test/resources/myfile.jks
我想从 Maven 项目的相对路径引用该资源。
所以我一直在尝试类似的事情:
keystore.file=${project.basedir}/web/src/test/resources/myfile.jks
我一直在读关于资源过滤 http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html其中提到这个问题 https://stackoverflow.com/questions/14763431/accessing-maven-pom-variables-from-properties-file.
该项目使用 SpringBoot,并且在运行 JUnit 时抱怨:
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'project.basedir' in string value "${project.basedir}/web/src/test/resources/myfile.jks"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174)
尝试不同的方法后,找到了解决我的问题的方法。
在 Spring Boot 中添加这一行application.properties
:
[email protected] /cdn-cgi/l/email-protection@
然后在config.properties
:
keystore.file=${maven.basedir}/web/src/test/resources/myfile.jks
让它发挥作用。
Check: Spring Boot 使用 Maven 自动扩展属性。 https://docs.spring.io/spring-boot/docs/current/reference/html/howto-properties-and-configuration.html#howto-automatic-expansion-maven
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)