Я установил пару конфигураций повтора в моем файле application.properties. Однако ни один из них не работает, когда я запускал ленточное приложение.
//this is my service
@RestController
@SpringBootApplication
public class HelloApplication {
@Value("${server.port}")
private int port;
public static void main(String[] args) {
SpringApplication.run(HelloApplication .class, args);
}
@GetMapping(value = "/app")
public String notification() {
return "This Is HelloService running on port:"+ port;
}
}
Вот мой класс RibbonAppApplication:
@SpringBootApplication(scanBasePackages = {"com.netflix.client.config.IClientConfig"})
@RestController
@RibbonClient(name= "hello", configuration=RibbonConfig.class )
public class RibbonAppApplication {
@Autowired
private RestTemplate restTemplate;
public static void main(String[] args) {
SpringApplication.run(RibbonAppApplication.class, args);
}
@GetMapping
public String getService() {
return restTemplate.getForObject("http://hello/app",String.class);
}
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
Это application.properties для RibbonAppApplication:
ribbon.eureka.enabled=false
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
hello.ribbon.listOfServers=http://localhost:1111, http://localhost:2222
hello.ribbon.OkToRetryOnAllOperations=false
hello.ribbon.MaxAutoRetries=0
hello.ribbon.MaxAutoRetriesNextServer=1
Спасибо вам, ребята, за помощь!




Отсутствие зависимости Sprint Retry почти всегда является причиной того, что Ribbon не может повторить попытку. Spring Retry - зависимость для функциональности повторных попыток для Zuul / Ribbon.
When a request fails, you may want to have the request be retried automatically. To do so when using Sping Cloud Netflix, you need to include Spring Retry on your application’s classpath. When Spring Retry is present, load-balanced RestTemplates, Feign, and Zuul automatically retry any failed requests (assuming your configuration allows doing so)
Добавление Spring Retry в pom.xml должно исправить это.
Связанные документы: https://cloud.spring.io/spring-cloud-netflix/multi/multi_retrying-failed-requests.html
Вы должны добавить зависимость spring-retry к вашему файлу pom.xml:
<!-- https://mvnrepository.com/artifact/org.springframework.retry/spring-retry -->
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
<version>1.2.4.RELEASE</version>
</dependency>