java 类型安全配置:从 src/test/resources 加载配置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29934698/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 16:08:48  来源:igfitidea点击:

Typesafe Config: Load configuration from src/test/resources

javaconfigurationakkatypesafetypesafe-stack

提问by daydreamer

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?

所以覆盖不起作用,为什么?

回答by cmbaxter

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.

基本ConfigFactory.load()方法会加载“application.conf”。如果你想让它加载一个不同的文件,你需要告诉它那个不同的文件是什么。