Spring util properties in app-context xml file

I am describing properties file in app-context.xml like this:

<?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:context="http://www.springframework.org/schema/context"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:task="http://www.springframework.org/schema/task"
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/jdbc 
        http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
        http://www.springframework.org/schema/task
        http://www.springframework.org/schema/task/spring-task.xsd
        http://www.springframework.org/schema/util 
        http://www.springframework.org/schema/util/spring-util.xsd">


    <context:annotation-config></context:annotation-config>

    <task:annotation-driven />


    <util:properties id="properties" location="file:/opt/vortal/VortalDataProvider/config/votral.properties"></util:properties>

</beans>

in any java file I am able to access this file through:

@Autowired
@Qualifier("properties")
private Properties properties;

However when I try to access properties in camel-context.xml

like:

<cxf:rsClient id="vortalEndpoint" address="${endpointUrl}" 
     serviceClass="pl.test.dataprovider.Processor"
     skipFaultLogging="false"/> 

value of bean vortalEndpoint is literally ${endpointUrl} – value from poperties is not read.

What am I doing wrong?

Answer

<util:properties>

initialized an instance of java.util.Properties class, check out the Doc. This is not the proper way to load your properties, if you are doing it in xml, you can use

<context:property-placeholder location="classpath:foo.properties" />

Then you can access your properties easily with

 @Value("${whatever}")
 private String myValue

Leave a Reply

Your email address will not be published. Required fields are marked *