Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to disable spring.config.import settings in the TestFiles? #1801

Closed
Miles-Ahead-Digital opened this issue Feb 17, 2021 · 9 comments
Closed

Comments

@Miles-Ahead-Digital
Copy link

Hi,
If I use the spring.config.import=optional:configserver in my application.yml (and no bootstrap.yml)
then I'm facing the following issue:

How can I deactivate the spring.config.import in my test classes??
It does not work with properties disabling like "spring.config.enabled=false"
I need to test without configserver.
Please advise

@ryanjbaxter
Copy link
Contributor

Did you forget to provide the issue?

@Miles-Ahead-Digital
Copy link
Author

I want to keep the TestCases and my StandardRuntime in the Spring Default Profile wich contains:
spring.config.import=optional:configserver

If I run my tests (without having the config server startet), the Test fail because it tries to use the config server. But for the TestCase there is no need to get the yml-config file from the ConfigServer - it works without it..

Best regards
Stefan

@ryanjbaxter
Copy link
Contributor

Can you provide a complete, minimal, verifiable sample that reproduces the problem? It should be available as a GitHub (or similar) project or attached to this issue as a zip file.

From my understanding that is not supposed to happen.

@Miles-Ahead-Digital
Copy link
Author

Hi,

i created https://github.com/Miles-Ahead-Digital/milesahead/tree/master

you can verify that the spring-profiles do not have any impact on the selection of the values served

Check the Readme.

Best regards
Stefan

@ryanjbaxter
Copy link
Contributor

@Miles-Ahead-Digital Not sure I understand how this sample demonstrates the issue. Your original problem stated that you were having problem with tests failing due to the conig server not running. I don't see how this sample reproduces that problem.

@Miles-Ahead-Digital
Copy link
Author

Miles-Ahead-Digital commented Feb 24, 2021

@ryanjbaxter
I added a TestCase in the Demo Module. Please read the instruction in the projects readme.
Best regards
Stefan

@ryanjbaxter
Copy link
Contributor

The problem you are having is because you are using the wrong properties in your application.yam. Change it to this and everything works

spring.application.name: demo

spring:
  config:
    import: optional:configserver:http://localhost:8888/

message: default-local

---
spring:
  config:
    activate:
      on-profile: test3

message: test3-local

---
spring:
  config:
    activate:
      on-profile: test10

message: test10-local

@Miles-Ahead-Digital
Copy link
Author

Miles-Ahead-Digital commented Mar 2, 2021

Thanks for correction. Of course this must be applied also to the files in the config-repo folder too.

The good thing is that the config server serves now the configuration as expected. Try
http://localhost:8888/demo/test1
http://localhost:8888/demo/test2
http://localhost:8888/demo/test3
http://localhost:8888/demo/test4

if you start the demo service without profile the default profile config
http://localhost:8888/demo/default is served correctly.
Check http://localhost:8080/message.

But starting the demo service with any other profile than default we get this error:

Property 'spring.config.activate.on-profile' imported from location '[ConfigServerConfigDataResource@6d8792db uris = array['http://localhost:8888/'], optional = true, profiles = list['test4']]' is invalid in a profile specific resource

This has already been reported:

#1788

If it is the same issue, you can close this one as a duplicate.

Thanks
Stefan

@ryanjbaxter
Copy link
Contributor

Agree appears to be the same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants