Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring property place holder is not resolving in jaxws:client (cxf) address property

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.

I'm using the below way to load the properties file.

@Configuration

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

Properties are getting resolved and no issues except in one case.

I'm using CXF for webservices and the address property is not getting resolved when "${addressVal}" is used. All other properties inside the xml are gettign loaded except for "jaxws:client".

<jaxws:client id="port"
        serviceClass="com.service.Myclass"
        address="${addressVal}" />
  1. Where is the problem. What I'm doing wrong.

  2. Problem with servlet context / application context loading ?

Please advice.

like image 202
viky S Avatar asked Dec 01 '15 04:12

viky S


1 Answers

I am having the same problem. Sadly no solution found yet. However, for anyone finding this question, a workaround is using the JaxWsProxyFactoryBean.

Example:

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

It is not as nice, becuase you have to inject the factory, call create() and cast, but at least it works.

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

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

You can also add the following to your spring config to create a specific bean, but that did not work for me. Trying to inject that bean failed, which is why I settled on the method described above.

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

See also http://cxf.apache.org/docs/writing-a-service-with-spring.html at the bottom of the page

like image 184
Vincentz Avatar answered Oct 13 '22 01:10

Vincentz