如何在Spring Boot中设置重试配置获取?

Artyom Karnov:

我有配置服务器,应用程序从该服务器获取配置。我想设置重试机制。如果配置服务器不可用,应用程序将发送请求10分钟。

在春季文档中,我找到了下一个配置

spring.cloud.config.uri=http://localhost:9090
spring.cloud.config.fail-fast=true
spring.cloud.config.retry.max-interval=10000
spring.cloud.config.retry.max-attempts=2000

但是他们什么也没改变。我的应用程序不重试请求,只是失败

Caused by: java.net.ConnectException: Connection refused: connect 

(此时配置服务器已关闭)

我究竟做错了什么?有办法解决我的问题吗?

Artyom Karnov:

我通过在上下文中添加下一个@Bean解决了我的问题

@Bean
    public RetryOperationsInterceptor configServerRetryInterceptor(RetryProperties properties) {
        return RetryInterceptorBuilder
                .stateless()
                .backOffOptions(properties.getInitialInterval(),
                        properties.getMultiplier(),
                        properties.getMaxInterval())
                .maxAttempts(properties.getMaxAttempts()).build();
    }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Spring Boot中设置过滤器链?

如何在Spring Boot中设置ActiveMQ端口?

如何在Spring Boot中设置休息的基本URL?

如何在Spring Boot应用程序中配置PageableHandlerMethodArgumentResolver

如何在Spring MVC 4中设置全局配置/变量?

如何在Java Spring Boot中为外部配置设置PropertySourcesPlaceholderConfigurer自动设置位置

如何在Spring Boot中配置拦截器?

如何在Spring Boot中配置SSL?

如何在Spring Boot配置中设置正确的MySQL JDBC时区

Spring Boot RabbitMQ连接重试配置

如何在Spring Boot Security中设置自己的权限?

如何在Spring Boot中从原始查询中获取数据?

如何在Spring Boot 2.1.9中配置SSL证书

如何在Spring Boot的application.yml中配置cassandra?

如何在Spring Boot中覆盖Spring Security默认配置

如何在Spring Boot中手动配置JdbcTemplate?

如何在Spring Boot应用程序的application.properties文件中设置MyBatis配置属性?

如何在spring-boot中设置context-param

如何在Spring Boot中为Camel配置Jackson ObjectMapper

如何在Spring Boot中配置CORS和基本授权?

如何在Spring Boot中配置Redis缓存?

如何在Spring Boot 2中配置Netty

我如何在Spring Boot中在DatabaseConfig中设置属性

如何在Spring Boot 2中配置https?

如何在jsr352中获取已配置的可重试/可跳过异常

如何在Spring Boot中为CosmosDb设置分区密钥

如何在Vertx中设置类似于Spring Boot的活动配置文件

如何在sts中更新Spring boot cli url配置?

如何在 Spring Boot 中为 @Cacheable 设置过期时间?