猿问

初始化上下文:属性占位符取决于 Maven 配置文件

我有一个名为 provider.xml 的 spring 文件


<context:property-placeholder location="classpath:META-INF/spring


/${build.profile.id}/config.properties" />

我有两个不同的 config.properties 一个在 META-INF/spring/ws1 中,另一个在 META-INF/spring/ws2


这是我的 pom.xml 的一部分


<profiles>

    <profile>

        <id>ws1</id>

        <properties>

            <build.profile.id>ws1</build.profile.id>

        </properties>

    </profile>

    <profile>

        <id>ws2</id>

        <properties>

            <build.profile.id>ws2</build.profile.id>

        </properties>

    </profile>

</profiles>

我收到此错误:


Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener

org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [META-INF/spring/${build.profile.id}/config.properties] cannot be opened because it does not exist

但是,如果我尝试在没有像这样的变量的情况下阅读它,它是有效的:


 <context:property-placeholder location="classpath:META-INF/spring/ws1/config.properties" /> 

如何在 context:property-placeholder 中将其作为变量读取?


在我将此代码添加到 provider.xml 之后


<bean id="propertyPlaceholderConfigurer"

class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />

<property name="searchSystemEnvironment" value="true" />

</bean>



元芳怎么了
浏览 124回答 2
2回答
随时随地看视频慕课网APP

相关分类

Java
我要回答