小编Nit*_*tro的帖子

Maven 3个不同的配置文件 - Spring propertyPlaceHolderConfig不能使用pom文件中的值

我在使用maven 3时遇到了一些问题并且正在加载正确的.properties文件.

我想要实现的目标如下:使用mvn -Plocal我想加载setting-local.properties,如果使用prod运行我想加载settings-prod.properties.

它通过使用mvn -Denv = local工作,但是当我尝试使用-Plocal时,未加载变量(settings - $ {env} .properties不存在).

我的pom.xml:

<profiles>
    <profile>
        <id>local</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <env>local</env>
        </properties>
    </profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)

在我的applicationcontext中,我想加载env-variable:

<bean id="propertyPlaceholderConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
                <list>
                        <value>classpath:settings-${env}.properties
                        </value>
                </list>
        </property>
        <property name="ignoreUnresolvablePlaceholders">
                <value>true</value>
        </property>
</bean>
Run Code Online (Sandbox Code Playgroud)

那么问题是什么,它不应该双向工作吗?

spring maven-3

3
推荐指数
1
解决办法
5962
查看次数

标签 统计

maven-3 ×1

spring ×1