简体   繁体   中英

Typesafe Config: Load configuration from src/test/resources

This is a beginner question. So my app structure looks like

src/main/java/...
src/main/resources/application.conf

src/test/java/...
src/test/resources/module/test.module.conf

application.conf

location: mainLocation

test.module.conf

location: testLocation

In my test, I do

  @Test
  public void testLoadConfig() {
    final Config config = ConfigFactory.parseResources("test.module.conf");
    System.out.println(config);
  }

and what I see

Config(SimpleConfigObject({}))

Surely something is not right, but I can't spot it

UPDATE

When I do just

  @Test
  public void testActorForFailure() {
//    final Config config = ConfigFactory.load("test.module.conf");
    final Config config = ConfigFactory.load();
    System.out.println(config.getString("location"));

  }

I see

mainLocation

So overriding is not working, why?

If you want to load that test config file try this:

ConfigFactory.load("modules/test.module")

The base ConfigFactory.load() method looks to load 'application.conf'. If you want it to load a different file you need to tell it what that different file is.

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