【问题标题】:Spring property place holder is not resolving in jaxws:client (cxf) address propertySpring 属性占位符未在 jaxws 中解析:客户端(cxf)地址属性
【发布时间】:2016-03-04 22:17:46
【问题描述】:
Environment:

    Spring MVC : 4.1.7.RELEASE
    CXF: 3.0.0
    java: 1.8

web.xml --- loads appContext.xml (spring cofigs) & cxfContext.xml (configs for cxf)

spring-servlet.xml --- loading the spring mvc configs.

我正在使用下面的方式来加载属性文件。

@Configuration

    @PropertySource(value = { "classpath:config.properties" })
    public class Configuration {
        @Bean
        public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
            return new PropertySourcesPlaceholderConfigurer();
        }
    }

属性正在得到解决,除了一种情况外没有任何问题。

我将 CXF 用于 Web 服务,但使用 "${addressVal}" 时地址属性未得到解析。除了 "jaxws:client" 之外,xml 中的所有其他属性都已加载。

<jaxws:client id="port"
        serviceClass="com.service.Myclass"
        address="${addressVal}" />
  1. 问题出在哪里。我做错了什么。

  2. servlet 上下文/应用程序上下文加载问题?

请指教。

【问题讨论】:

  • 使用命名空间时,由该命名空间的实现者来正确解析占位符,如果没有实现,它将不起作用。
  • 亲爱的 M.Deinum, 感谢您的评论。 “jaxws:client”是 CXF 给出的命名空间。 (cxf.apache.org/jaxwscxf.apache.org/schemas/jaxws.xsd">)。当没有 Spring MVC 时,它更早地工作。但是当我们转移到 Spring MVC 时,它并没有解析属性。
  • 如果它工作正常,您更改了配置中的某些内容。我的猜测是您的 cxf 内容加载在未加载/使用 PropertySourcesPlaceholderConfigurer 的配置中。
  • 我们对整个框架进行了改进,将 Spring MVC 用于 REST 控制器。我正在将 cxf 的东西加载到 xml 中(cxf 内部仅使用 spring)并且 xml 直接加载到 web.xml 中尝试了我能想到但无法缩小范围的所有可能性。
  • 如果你有一个ContextLoaderListener 和一个DispatcherServlet 没关系,你有2个上下文,如果属性被加载到1并且其他你的属性中的cxc东西不可用.

标签: spring spring-mvc cxf jax-ws spring-cxf


【解决方案1】:

我也有同样的问题。遗憾的是还没有找到解决方案。但是,对于任何发现此问题的人,解决方法是使用 JaxWsProxyFactoryBean。

例子:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schema/jaxws.xsd">
<bean id="client" class="demo.spring.service.HelloWorld" factory-bean="clientFactory" factory-method="create"/>
<bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
    <property name="serviceClass" value="demo.spring.service.HelloWorld"/>
    <property name="address" value="${some.property.value}"/>
</bean>

它不是那么好,因为你必须注入工厂,调用 create() 并强制转换,但至少它可以工作。

@Autowired
@Qualifier("clientFactory")
private JaxWsProxyFactoryBean factory;

public void callService() {
    HelloWorld helloWorld = (demo.spring.service.HelloWorld)factory.create();
}

您还可以将以下内容添加到您的 spring 配置中以创建特定的 bean,但这对我不起作用。尝试注入该 bean 失败,这就是我选择上述方法的原因。

<bean id="client" class="demo.spring.service.HelloWorld" factory-bean="clientFactory" factory-method="create"/>

另请参阅页面底部的http://cxf.apache.org/docs/writing-a-service-with-spring.html

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-22
  • 2021-03-08
  • 2014-03-23
  • 1970-01-01
  • 2012-08-03
  • 2015-01-16
相关资源
最近更新 更多