简体   繁体   中英

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. 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 . 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. When the application is deployed into AWS environment then the Resilience4J related properties are not read.

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. 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. In AWS I am using java-11-openjdk in amazon-linux platform. 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.

@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. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM