the service has been registered, as shown in figure
the service invocation code is as follows:
Startup class:
@SpringCloudApplication
public class RibbonConsumerApplication {
public static void main(String[] args) {
SpringApplication.run(RibbonConsumerApplication.class, args);
}
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
RestTemplate restTemplate = new RestTemplate();
return restTemplate;
}
}
// Controller
@RestController
public class ConsumerController {
@Autowired
RestTemplate restTemplate;
@RequestMapping(value = "/ribbon-consumer", method = RequestMethod.GET)
public String helloController() {
String url = "http://HELLOSERVICE/hello";
ResponseEntity<String> forEntity = restTemplate.getForEntity(url, String.class);
return forEntity.getBody();
}
public String error() {
return "error";
}
}
configuration file application.properties
spring.application.name=ribbon-consumer
server.port=9111
eureka.client.service-url.defaultZone= http://localhost:1111/eureka
but always report an error:
java.net.UnknownHostException: HELLOSERVICE