2

I have written an application that calls a service through Spring's RestTemplate. It's working fine when I call the URL http://localhost:8081/index/myservice directly. I tried configuring an endpoint using application.properties, how do I link it to the method calling the URL ? As it is now, It doesn't have any effect.

application.properties

 app.endpoint = http://localhost:8081/index/

I want to directly call app.endpoint instead of writing the URL.

Update : ApplicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">


 <!-- Rest Template -->  

<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">  
</bean>

<bean id="properties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
    <list><value>classpath:application.properties</value></list>
</property>

Mel
  • 453
  • 1
  • 4
  • 14
  • Have you tried using : ${app.endpoint} ? Check out the steps here : http://stackoverflow.com/questions/3933862/how-to-use-property-from-property-file-specified-in-propertyplaceholderconfigure – Gyan Mar 20 '15 at 10:02
  • do post here if that does not work out. – Gyan Mar 20 '15 at 10:11
  • I've configured the ApplicationContext but I don't know how to call ${app.endpoint} ? if I put it just like that, it isn't reconized. – Mel Mar 20 '15 at 10:16
  • can you post the xml pls ? Please note, this is for use in the JSP. If your resttemplate is configured in the context xml, you can use PropertyPlaceholderConfigurer. – Gyan Mar 20 '15 at 10:31
  • That might be, I didn't copy the jsp part since I didn't use Jsp. Updated question. – Mel Mar 20 '15 at 10:39

1 Answers1

0

So to call the URL from the method : You can use the @Value annotation like this :

@Value("${app.endpoint}") private String appEndpoint;

The configuration in your XML :
<context:property-placeholder location="classpath:placeholder.properties"/>

HTH, Gyan

Gyan
  • 1,176
  • 1
  • 12
  • 26