Results 1 to 2 of 2

Thread: <util:properties and @Value not working

  1. #1

    Angry <util:properties and @Value not working

    Hi,

    I am calling a SOAP web service using Spring's WebServiceGatewaySupport.

    It works fine, but I now need to externalize the endpoint ipAddress. Since the
    endpoint is used in several methods in the class, I've defined the endpoint as
    a class variable.

    I've defined a text property file, utilroperties in applicationContext.xml, and @Value in the class.
    When I don't reference the value in my class, the app starts fine so I know Spring is finding
    my properties file and correlating it to the @Value.

    However, I get a 'could not resolve placeholder' error with @Value("${myProp.ipAddress}") syntax.
    With @Value("${myProp['ipAddress']}") syntax I get a null value in the ipAddress field.

    I've tried both the static $ and dynamic # tags, to no avail. Is it possible that Spring won't
    retrieve the value until after the class is instantiated ? If so, how do I get an externalized
    endpoint ipAddress into my class ?

    The code is below.

    Please help !!!

    appContext

    Code:
    <util:properties id="myProp" location="/WEB-INF/properties/myProperties"/>
    property file

    Code:
    ipAddress=http://192.168.22.33:5897
    @Value bits in the class

    Code:
    @Service
    public class MyClass extends WebServiceGatewaySupport implements IMyClass
    {
    
            @Value("${myProp.ipAddress}") // (or @Value("${myProp['ipAddress']}")
    	public void setIpAddress(String ipAddress)
    	{
    		this.ipAddress = ipAddress;
    	}
    
    	MySoapProxy mySoapProxy = new MySoapProxy(ipAddress + "/MySoapService?wsdl");
    
    ...
    Last edited by Slidewayz; Oct 19th, 2011 at 11:34 PM.

  2. #2

    Default

    OK, I cracked it.

    I set the value of the endpoint url within a @PostConstruct method. Therefore, the reason
    why this wasn't working was because the property isn't set by Spring until after all the
    properties in the class are instantiated.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •