2

I have an spring-boot application that uses config server. In project I have a bootstrap.yml:

spring:
 cloud:
    config:
      uri: ${CLOUD_CONFIG_URI:http://localhost:8888}
      failFast: true
      enabled: ??

and I can pass actual config for server location through parameter. That's ok.

With this configuration I don't know how to disable this in integration tests. My tests load this configuration and want to communicate with config server. I know that I can pass spring.cloud.config.enabled=false but it's not a solution (I want to right click in IDE and run test without additional configuration per each test method).

Any idea?

6
  • 1
    have tried using spring-profile for your integration tests? Commented Jul 26, 2018 at 12:01
  • 1
    Could you please suggest how to use profiles here? Ideal solution would be to use 'test' profile for enabled option (enabled if active profile is different than 'test'), but how to do this ? Commented Jul 26, 2018 at 12:49
  • 1
    You can use @Profile("test") at class level and add spring.profiles.active=test,dev in application.yml or appliation.properties file and use -Dspring.profiles.active=test while running the code.. Commented Jul 26, 2018 at 13:33
  • You are right, but how this can solve my issue? I have test profile enabled with tests. How to use this profile to disable config server ? Commented Jul 27, 2018 at 6:41
  • 1
    No, Spring loads properties from config server before local files, therefore disable it in test profile / test properties doesn't work Commented Jul 28, 2018 at 8:49

1 Answer 1

4

This is a late answer but for the people that join from any search engines here is my solution:

The @Profile("test") annotation above your integration test class is correct. To get this really working is adding two extra configuration files to your normal resources folder, not the test resources folder.

  1. Add "application-test.yml"
  2. Add "bootstrap-test.yml"

In your bootstrap-test.yml add the following:

spring:
    cloud:
        config:
          enabled: false

With this configuration you can put all of your needed configuration options in the application-test.yml and the bootstrap-test.yml will disabled spring cloud config.

Sign up to request clarification or add additional context in comments.

2 Comments

So, how I do if I must get data from repository to use on integrationTest?
@Augusto This is an approach in case your integration test would like to avoid connecting to the config server

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.