I am using spring boot with spring could ribbon. I did all configuration of ribbon. But when I send a request to rest controller, it throws an exception called No instances available for serverurl. How can I fix this?
These are my configurations
application.yml
port: 8888
serverurl:
ribbon:
eureka:
enabled: false
listOfServers: localhost:8081,localhost:8082,localhost:8083
ServerListRefreshInterval: 15000
Spring Boot Main Class
@SpringBootApplication
@RibbonClient(name = "serverurl", configuration = RibbonCongisuration.class)
public class Server {
@LoadBalanced
@Bean
RestTemplate restTemplate(){
return new RestTemplate();
}
public static void main(String[] args) {
SpringApplication.run(Server.class,args);
}
}
Rest Controller
@RestController
@RequestMapping(value = "api/v1/clients")
public class ClientController {
@Autowired
RestTemplate restTemplate;
@GetMapping(value = "/{ID}")
public ClientDTO findByID(@PathVariable("ID") String clientID){
return restTemplate.getForEntity("http://serverurl/api/v1/clients/"+clientID,ClientDTO.class).getBody();
}
}
URL
http://localhost:8888/api/v1/clients/1234