0

我正在使用 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}

这是项目结构

项目结构

这是我的配置 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);

    }
}

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

4

0 回答 0