In my Spring proejct, I created a config.conf
to store some variables.
And in a class I need to read these variables.
I am using the config
library, https://github.com/lightbend/config .
And as the document says, I tried to used
private static final Config config = ConfigFactory.load(basename here goes here);
to load that config.conf
file.
And by the document, https://lightbend.github.io/config/latest/api/com/typesafe/config/ConfigFactory.html#load-java.lang.String- , this method receives a string as classpath resource basename.
I am wondering how to get this "classpath resource basename" of the config.conf
file?
My project's structure:
Thanks!
you can access file like this.
URL url = EmailService.class.getClassLoader().getResource("config.conf");
to load config, you can access path like below
config.load(url.getPath());
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.