简体   繁体   English

对于导入上下文中的bean,不会解析PropertyPlaceholderConfigurer值

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

I have PropertyPlaceholderConfigurer configured in my web application's Spring context which in turn imports few other contexts which are in JARs that expect certain properties to be configured. 我在我的Web应用程序的Spring上下文中配置了PropertyPlaceholderConfigurer,后者又导入了JAR中的其他几个需要配置某些属性的上下文。 But for some reason the PropertyPlaceholderConfigurer values ware not available to them and I get error on start up: 但由于某些原因,PropertyPlaceholderConfigurer值无法使用,我在启动时遇到错误:

java.net.URISyntaxException: Illegalcharacter in path at index 1: ${dax.svc1.endpoint} java.net.URISyntaxException:索引1处路径中的非法字符:$ {dax.svc1.endpoint}

Here is what my application context looks like: 这是我的应用程序上下文的样子:

<?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>

Child context is like this : 子上下文是这样的:

<?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>

I verified the property file is on the classpath and has the property dax.svc1.endpoint . 我验证了属性文件在类路径上并具有属性dax.svc1.endpoint What am I missing here? 我在这里错过了什么?

我将假设您拥有所有xml指令...检查属性文件的编码(也是您的XML)

You have to put a placeholder bean inside each of the imports; 你必须在每个导入中放置一个占位符bean; that's the only way I could get it to work as I have a similar setup to what you describe. 这是我能够让它工作的唯一方式,因为我有类似于你描述的设置。 I also removed the id from the bean to prevent any id conflicts in the container. 我还从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.

相关问题 春天-应用程序上下文中的bean是否动态绑定到PropertyPlaceholderConfigurer? - spring — are beans in application context binded to PropertyPlaceholderConfigurer dynamically? 如何将tomcat context.xml参数值获取到Spring PropertyPlaceholderConfigurer中 - How to get tomcat context.xml Parameters values into spring PropertyPlaceholderConfigurer PropertyPlaceholderConfigurer与过滤器—春季豆 - PropertyPlaceholderConfigurer vs Filters — Spring Beans Spring - 设置从不同上下文文件导入的bean的属性 - Spring - Set properties on beans imported from a different context file Spring:在没有Singelton Beans的情况下以编程方式使用PropertyPlaceHolderConfigurer - Spring: Programmatically use PropertyPlaceHolderConfigurer on none Singelton Beans PropertyPlaceHolderConfigurer不读取Tomcat上下文XML - PropertyPlaceHolderConfigurer not reading Tomcat context XML 导入了JSON库Java,但仍然无法解析JSON错误 - Imported json library Java, but still getting JSON cannot be resolved error Spring PropertyPlaceholderConfigurer和具有多个值的键 - Spring PropertyPlaceholderConfigurer and keys with multiple values 无法使用PropertyPlaceholderConfigurer在JNDI上下文中找到属性 - Unable to find property in JNDI context using PropertyPlaceholderConfigurer 春季:在应用程序上下文之外使用PropertyPlaceholderConfigurer支持 - Spring: Using PropertyPlaceholderConfigurer support outside of application context
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM