Java 弹簧罐';t解析命令行参数

Java 弹簧罐';t解析命令行参数,java,spring,spring-mvc,spring-boot,Java,Spring,Spring Mvc,Spring Boot,我正在将一个非常传统的应用程序迁移到Spring Boot。它是用xml配置的,我有以下代码片段: <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="localOverride" value="true"/> <property name="locations"> <li

我正在将一个非常传统的应用程序迁移到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>
但它在启动时失败,并显示以下消息:

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'ENV' in value "classpath:conf/${ENV}/some.properties"
它以前工作过,现在我有了
springbootstarterweb

有什么建议吗?提前谢谢你


更新:它在
@PropertySource
中不起作用,不是在xml中,很抱歉在使用maven spring启动插件运行应用程序时(就像您正在做的那样)会产生误解,您需要这样指定

mvn spring-boot:run -Drun.arguments="--server.port=22222, --ENV=int"
如果您想使用
java-jar
命令运行应用程序。就是这样

java -jar -Dserver.port=22222 -DENV=int XYZ.jar
您应该使用
#systemEnvironment['propertyName']

{systemProperties['propertyName']}

 <value>classpath:conf/#{systemEnvironment['ENV']/some.properties</value>

您只能访问
.properties
文件中定义的属性,谢谢您的回答,但现在它说“无法解析命令行选项:无法识别的选项:--ENV=int”抱歉,我刚刚发现一个真正的问题:它在PropertySource注释中不起作用。你有什么建议吗?你如何在
@PropertySource
中这样使用:@PropertySource({“classpath:conf/${ENV}/some.properties”})这个conf文件夹在哪里?非常感谢,但我刚刚发现它在PropertySource注释中不起作用。但是,它以前使用过${}。您使用的是哪种spring启动版本?您能否确认在target/classes和JAR包中可以找到配置文件。@Blourr您好,Spring Boot版本是1.4.7,不,没有此配置,但问题在于解决环境变量,而不是JAR)
 <value>classpath:conf/#{systemEnvironment['ENV']/some.properties</value>
${propertyName}