1

I've a Spring boot application with a classic bootstrap who will get the settings in a git repo :

# =====================================
# = Common properties for every profile
# =====================================
spring:
  application:
    name: myapplication

---

# ====================================
# = local profile
# ====================================

spring:
  config:
    activate:
      on-profile: local
  cloud:
    config:
      uri: http://localhost:8000

---

If I run this application, it works perfectly but I've a mistake when I run the unit test.

For the moment, I only have the basic unique test :

@SpringBootTest
class MyApplicationTests {

    @Test
    void contextLoads() {
    }

}

This error is due to the context load :

java.lang.IllegalStateException: Failed to load ApplicationContext

    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132)

And I understand why : when the test is running, I don't know why, but the application try to load the config files from localhost:8888 and not localhost:8000, like it's setted in the bootstrap.

I suppose it's a "by default" config, but how can I tell to the test to find the config file in the good port?

Greg
  • 127
  • 1
  • 15
  • Does this answer your question? [Failed to load ApplicationContext from Unit Test: FileNotFound](https://stackoverflow.com/questions/24776669/failed-to-load-applicationcontext-from-unit-test-filenotfound) –  Feb 02 '22 at 10:55
  • 1
    You didn't enable the profile `local` at leat not in your test, so it will use the defaults. – M. Deinum Feb 02 '22 at 11:13
  • Yes, it was the problem. Thx for your help! – Greg Feb 03 '22 at 12:55

0 Answers0