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

1

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

Prism answered 1/12, 2015 at 4:52 Comment(6)
When a namespace is used it is up to the implementor of that namespace to correctly resolve placeholders, if that isn't implemented it will not work.Taranto
Dear M.Deinum, Thanks for the comment. "jaxws:client" is the namespace given by CXF. (cxf.apache.org/jaxws cxf.apache.org/schemas/jaxws.xsd">). It was working earlier when there was no spring MVC. But when we moved to spring MVC, it is not resolving the property.Prism
If it was working you changed something in your configuration. My guess is your cxf stuff is loaded in a configuration that isn't loading/using the PropertySourcesPlaceholderConfigurer.Taranto
We revamped the entire framework to use Spring MVC for REST controllers. I'm loading the cxf stuff in an xml (cxf internally uses spring only) and that xml is directly loaded in the web.xml Tried all possibilities I could think of but couldn't narrow down.Prism
That doesn't matter if you have a ContextLoaderListener and a DispatcherServlet you have 2 contexts, if the properties are loaded in 1 and the cxc stuff in the other your properties aren't available.Taranto
But other properties are getting updated except for one namespace. How to make it working inside the xml file for "jaxws:client" namespace..Prism
N
3

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

Natation answered 15/5, 2017 at 13:19 Comment(1)
Thank you very much for the workaround. Basically this issue seems to be the jira.spring.io/browse/SPR-15827Deeply

© 2022 - 2024 — McMap. All rights reserved.