在使用SpringCloud搭建微服务的时候,消费者应用通过RestTemplate来向服务提供者发送GET请求,但是报Connection refused: connect错误,如下:我的配置文件如下:
注册中心:
server.port=8888
eureka.instance.hostname=localhost
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/
服务提供者:
server.servlet.context-path=/itsq.sysAuth
server.address=127.0.0.1
server.tomcat.remote_ip_header=x-forwarded-for
server.tomcat.protocol_header=x-forwarded-proto
server.tomcat.port-header=X-Forwarded-Port
server.use-forward-headers=true
logging.level.org.springframework=INFOspring.application.name=sysAuth-client
server.port=8080
eureka.client.serviceUrl.defaultZone=http://localhost:8888/eureka/
消费者:
server.servlet.context-path=/itsq.fremework
server.address=127.0.0.1
server.tomcat.remote_ip_header=x-forwarded-for
server.tomcat.protocol_header=x-forwarded-proto
server.tomcat.port-header=X-Forwarded-Port
server.use-forward-headers=true
logging.level.org.springframework=INFO
spring.application.name=fremework-client
server.port=8081
eureka.client.service-url.defaultZone=http://localhost:8888/eureka/
调用方式:
@RestController
public class HelloController {

@Autowired
    private RestTemplate restTemplate;

@RequestMapping(value = "/hello",method = RequestMethod.GET)
    public String helloController() {
        return restTemplate.getForEntity("http://SYSAUTH-CLIENT/hello", String.class).getBody();
    }
}