在Spring Boot中无法使用context:property-placeholder读取application.properties文件的值

时间:2018-10-24 07:46:40

标签: spring-boot environment-variables application.properties property-placeholder

我正在将application.properties文件用于一般配置,我打算稍后对其进行配置文件。现在,我正在使用另一个配置文件root-context.xml,其中配置了jaxws客户端bean。我想使用上下文属性占位符从application.properties文件传递该bean配置的终结点地址,但是它使我以下错误:

Caused by: java.io.IOException: java.net.URISyntaxException: Illegal character in path at index 1: ${sample_endpoint}

这是项目结构

project structure

这是我的配置 src / main / resources / application.properites

config.monitor.dir=C:\/Users/xxx/Documents/resources/artifacts
application.config.file.name=application-config
sample_endpoint=http://xx.x.x/sampleInquiry/01

src / main / resources / root-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:cxf="http://cxf.apache.org/core"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
       http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
       http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">


    <context:property-placeholder location="classpath:application.properties"/>

    <bean id="messagesSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basenames">
            <list>

                <value>file:${config.monitor.dir}/${application.messages.file.name}
                </value>
            </list>
        </property>
        <property name="cacheSeconds" value="30" />
        <property name="defaultEncoding" value="UTF-8" />
    </bean>

    <bean id="messages"
        class="com.project.microservices.sampleproject.config.Messages"
        scope="application">
        <property name="messagesSource" ref="messagesSource" />
    </bean>


    <jaxws:client id="sampleClient" serviceClass="com.sample.wsdl.sampleInq"
        address="${sample_endpoint}">

        <jaxws:inInterceptors>
            <bean class="org.apache.cxf.interceptor.LoggingInInterceptor" />
            <!-- <ref bean="loggingInInterceptor" /> -->
        </jaxws:inInterceptors>
        <jaxws:outInterceptors>
            <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor" />
            <!-- <ref bean="loggingOutInterceptor" /> -->
            <bean class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">
                <constructor-arg>
                    <map>
                        <entry key="action" value="UsernameToken" />
                        <entry key="user" value="website" />
                        <entry key="user" value="website" />
                        <entry key="passwordType" value="PasswordText" />
                        <entry key="passwordCallbackRef" value-ref="myPasswordCallback" />
                    </map>
                </constructor-arg>
            </bean>
        </jaxws:outInterceptors>
    </jaxws:client>

主班

@SpringBootApplication
public class SampleApplication extends SpringBootServletInitializer implements WebApplicationInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SampleApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(SampleApplication.class, args);

    }
}

还有一点,应用程序能够解析文件:$ {config.monitor.dir} / $ {application.messages.file.name}值在根上下文中提及,但在端点地址中没有提及。 我在这里想念什么?请帮助。我正在使用引导版本1.5.17

0 个答案:

没有答案