Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在RestTemplate中链接端点_Java_Spring_Resttemplate - Fatal编程技术网

Java 在RestTemplate中链接端点

Java 在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

我已经编写了一个通过Spring的RestTemplate调用服务的应用程序。 当我调用URL
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。