簡體   English   中英

對於導入上下文中的bean,不會解析PropertyPlaceholderConfigurer值

[英]PropertyPlaceholderConfigurer values are not getting resolved for beans in imported context

我在我的Web應用程序的Spring上下文中配置了PropertyPlaceholderConfigurer,后者又導入了JAR中的其他幾個需要配置某些屬性的上下文。 但由於某些原因,PropertyPlaceholderConfigurer值無法使用,我在啟動時遇到錯誤:

java.net.URISyntaxException:索引1處路徑中的非法字符:$ {dax.svc1.endpoint}

這是我的應用程序上下文的樣子:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:util="http://www.springframework.org/schema/util" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd    
     http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd    
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" name="mhpVariables">
        <property name="locations">
            <list>
                <value>classpath:appconfig.properties</value>
            </list>
        </property>
    </bean>
    <import resource="classpath:com.test.svc1/childContext.xml"/>
    <import resource="classpath:com.test.svc2/child2Context.xml"/>
</beans>

子上下文是這樣的:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:util="http://www.springframework.org/schema/util" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    <!-- connection info -->
    <bean class="com.test.java.framework.dataaccess.ServiceConnectionInfo" id="ConnectionInfo">
        <property name="defaultUri" value="${dax.svc1.endpoint}"/>
        <property name="maxTotalConnections" value="500"/>
        <property name="maxConnectionsPerHost" value="50"/>
        <property name="readTimeout" value="3000"/>
        <property name="ConnectionTimeout" value="1000"/>
    </bean>
</beans>

我驗證了屬性文件在類路徑上並具有屬性dax.svc1.endpoint 我在這里錯過了什么?

我將假設您擁有所有xml指令...檢查屬性文件的編碼(也是您的XML)

你必須在每個導入中放置一個占位符bean; 這是我能夠讓它工作的唯一方式,因為我有類似於你描述的設置。 我還從bean中刪除了id以防止容器中的任何id沖突。

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="WEB-INF/myconfig.properties" />
</bean> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM