Reputation: 631
I have a spring boot application with configuation like this:
src/main/resources/application.yml:
eureka:
client:
serviceUrl:
defaultZone: http://10.254.102.12:1111/eureka/
In my unit test cases, I want to set eureka instance name and change the logging level. src/test/resources/application.yml:
eureka:
instance:
appname: item-client-test
logging:
level: debug
But when I added these additional settings those former settings seems to not work any more. The eureka serviceUrl fallback to default loclahost:8761, so my test failed. When I added my custom eureka serviceUrl to src/test/resources/application.yml
, my test goes well.
So I am confused about is this a bug of spring boot or I was not using the right way for my configuration?
Upvotes: 0
Views: 229
Reputation: 7279
What you can try, instead, is having two configuration files like:
src/main/resources/application.yml
eureka:
client:
serviceUrl:
defaultZone: http://10.254.102.12:1111/eureka/
and
src/main/resources/application-test.yml
eureka:
instance:
appname: item-client-test
client:
serviceUrl:
defaultZone: http://test-server/eureka/
logging:
level: debug
and run your tests with SPRING_PROFILES_ACTIVE=test mvn test
Spring Boot will look for application-#{environment}
config file (so to say) and use it, inheriting from the default (application.yml
) config file
Upvotes: 1