![](/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.