Java 在RestTemplate中链接端点
我已经编写了一个通过Spring的RestTemplate调用服务的应用程序。 当我调用URLJava 在RestTemplate中链接端点,java,spring,resttemplate,Java,Spring,Resttemplate,我已经编写了一个通过Spring的RestTemplate调用服务的应用程序。 当我调用URLhttp://localhost:8081/index/myservice直接输入。 我尝试使用application.properties配置端点,如何将其链接到调用URL的方法?现在,它没有任何效果 应用程序属性 app.endpoint = http://localhost:8081/index/ 我想直接调用app.endpoint,而不是编写URL 更新:ApplicationContex
http://localhost:8081/index/myservice
直接输入。
我尝试使用application.properties
配置端点,如何将其链接到调用URL的方法?现在,它没有任何效果
应用程序属性
app.endpoint = http://localhost:8081/index/
我想直接调用app.endpoint
,而不是编写URL
更新: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>
类路径:application.properties
因此,要从方法调用URL,可以使用@Value注释,如下所示:
@Value(“${app.endpoint}”)
私有字符串附加点代码>
XML中的配置:
嗯,,
Gyan您是否尝试过使用:${app.endpoint}?请查看此处的步骤:我会尝试一下,谢谢。如果不成功,请在此处发布。我已经配置了ApplicationContext,但我不知道如何调用${app.endpoint}?如果我这样说的话,它不会被重新确认。你能发布xml吗?请注意,这是在JSP中使用的。如果在上下文xml中配置了resttemplate,则可以使用PropertyPlaceHolderConfigure。