我正在将一个相当旧的应用程序迁移到 Spring Boot。它是用 xml 配置的,我在那里有以下代码片段:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="localOverride" value="true"/>
<property name="locations">
<list>
<value>classpath:conf/${ENV}/some.properties</value>
</list>
</property>
</bean>
我使用以下命令行启动应用程序:
mvn spring-boot:run -Dserver.port=22222 -DENV=int
但启动失败并显示以下消息:
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'ENV' in value "classpath:conf/${ENV}/some.properties"
它以前有效,现在我有了 spring-boot-starter-web
。
有什么建议吗?预先感谢您!
更新:它在@PropertySource
中不起作用,在xml中不起作用,抱歉造成误解
最佳答案
当使用maven spring boot插件运行应用程序时(就像你正在做的那样),你需要像这样指定
mvn spring-boot:run -Drun.arguments="--server.port=22222, --ENV=int"
如果您想使用java -jar
命令运行应用程序。就是这样
java -jar -Dserver.port=22222 -DENV=int XYZ.jar
关于java - Spring无法解析命令行参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48112560/