![](/img/trans.png)
[英]How to use a file-resource instead of a classpath-resource in ibatis sqlMap config?
[英]How to get the classpath resource basename of a config file in Spring proejct?
在我的 Spring 项目中,我创建了一个config.conf
来存储一些变量。
在 class 中,我需要读取这些变量。
我正在使用config
库https://github.com/lightbend/config 。
正如文件所说,我试图使用
private static final Config config = ConfigFactory.load(basename here goes here);
加载该config.conf
文件。
根据文档https://lightbend.github.io/config/latest/api/com/typesafe/config/ConfigFactory.html#load-java.lang.String- ,该方法接收一个字符串作为类路径资源基名。
我想知道如何获取config.conf
文件的“类路径资源基名”?
我的项目结构:
谢谢!
你可以像这样访问文件。
URL url = EmailService.class.getClassLoader().getResource("config.conf");
要加载配置,您可以访问如下路径
config.load(url.getPath());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.