[英]Spring boot application properties are not reading in AWS environment
Apparently, myself along with my team is facing an issue related to our spring boot application's application.yml
file.显然,我和我的团队正面临与我们的 spring 引导应用程序的
application.yml
文件相关的问题。 We did attempt to solve this issue for over three days and still unable to figure out what went wrong.我们确实尝试了三天多来解决这个问题,但仍然无法弄清楚出了什么问题。
This issue is with the application.yml
used in spring-cloud-starter-circuitbreaker-resilience4j
with version 2.1.3
.此问题与版本
2.1.3
的spring-cloud-starter-circuitbreaker-resilience4j
中使用的application.yml
相关。 All other application properties related to other libraries are working fine.与其他库相关的所有其他应用程序属性都可以正常工作。 However, in my local PC, all the test cases and Maven build is successful including Resilience4J related properties.
但是,在我的本地 PC 中,所有测试用例和 Maven 构建都成功,包括 Resilience4J 相关属性。 When the application is deployed into AWS environment then the Resilience4J related properties are not read.
当应用程序部署到 AWS 环境中时,不会读取 Resilience4J 相关属性。
I have no clue how does this happen.我不知道这是怎么发生的。 It works fine in local environment and does not work on AWS environment but only Resilience4J related application properties.
它在本地环境中运行良好,不适用于 AWS 环境,仅适用于 Resilience4J 相关的应用程序属性。 I will add the application properties I am using as well.
我还将添加我正在使用的应用程序属性。
resilience4j:
circuitbreaker:
instances:
backendA:
registerHealthIndicator: true
slidingWindowSize: 3
minimumNumberOfCalls: 4
permittedNumberOfCallsInHalfOpenState: 3
automaticTransitionFromOpenToHalfOpenEnabled: true
waitDurationInOpenState: 10s
failureRateThreshold: 50
eventConsumerBufferSize: 10
recordExceptions:
- org.springframework.web.client.HttpServerErrorException
- org.springframework.web.client.RestClientException
- java.util.concurrent.TimeoutException
- java.io.IOException
ignoreExceptions:
- org.springframework.web.client.ResourceAccessException
Sample code usage is also added bellow.下面还添加了示例代码用法。
import org.springframework.cloud.client.circuitbreaker.CircuitBreaker;
import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory;
@Override
public String getRemoteData(boolean isRequestTimeout) {
CircuitBreaker circuitBreaker = circuitBreakerFactory.create("backendTest");
String remoteUrl = url + "circuit-breaker/sample-data";
if (isRequestTimeout) {
remoteUrl = "http://localhost:8090/invalid-endpoint"; //invalid uri
}
String finalRemoteUrl = remoteUrl;
return circuitBreaker.run(
() -> {
log.info("CircuitBreaker Caller Method");
return longTimeoutRestTemplate.getForObject(finalRemoteUrl, String.class);
}
, throwable -> getDefaultList());
}
I am using java 11
and locally built with maven 3.8.1
in windows
platform.我正在使用
java 11
并在windows
平台中使用maven 3.8.1
本地构建。 In AWS I am using java-11-openjdk
in amazon-linux
platform.在 AWS 中,我在
amazon-linux
平台上使用java-11-openjdk
。 This issue may sounds weird and impossible but I have no logical explanation on how does this happen in this way.这个问题可能听起来很奇怪而且不可能,但我没有逻辑解释这是如何以这种方式发生的。 Please help me to figure this out and thank you.
请帮我解决这个问题,谢谢。
Something new to add要添加的新内容
If we declare another java class to get those application properties and create the factory bean, then it works.如果我们声明另一个 java class 来获取这些应用程序属性并创建工厂 bean,那么它可以工作。
@Bean
public Customizer<Resilience4JCircuitBreakerFactory> specificCustomConfiguration1() {
TimeLimiterConfig timeLimiterConfig = TimeLimiterConfig.custom()
.timeoutDuration(Duration.ofSeconds(4))
.build();
CircuitBreakerConfig circuitBreakerConfig = CircuitBreakerConfig.custom()
.failureRateThreshold(50)
.waitDurationInOpenState(Duration.ofMillis(10000))
.slidingWindowSize(2)
.build();
return factory -> factory.configure(builder -> builder.circuitBreakerConfig(circuitBreakerConfig)
.timeLimiterConfig(timeLimiterConfig).build(), "backendTest");
}
This manual @Bean
creation is not mandatory and the library should read the application.yml
file and create the @Bean
factory.此手动创建
@Bean
不是强制性的,库应读取application.yml
文件并创建@Bean
工厂。 If the above code is missing, then the factory is created with default configuration properties.如果缺少上述代码,则使用默认配置属性创建工厂。
We were investigating this issue and unable to really figure-out the root cause.我们正在调查这个问题,但无法真正找出根本原因。 However we could overcome this issue.
但是我们可以克服这个问题。 I have no logical explanation for the moment to support how come this fixes the issue but anyway I will mention it here since it might help someone if ever come across the same issue.
目前我没有合乎逻辑的解释来支持这如何解决问题,但无论如何我会在这里提到它,因为如果遇到同样的问题它可能会对某人有所帮助。
My issue is solved after removing the following configuration from the application.yml
file.从
application.yml
文件中删除以下配置后,我的问题得到解决。
recordExceptions:
- org.springframework.web.client.HttpServerErrorException
- org.springframework.web.client.RestClientException
- java.util.concurrent.TimeoutException
- java.io.IOException
ignoreExceptions:
- org.springframework.web.client.ResourceAccessException
Again, I have no clue to explain the fix but until I figure out the problem, this might help.同样,我不知道如何解释修复,但在我弄清楚问题之前,这可能会有所帮助。 Thanks
谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.