Load properties file in servlet?

后端 未结 2 1394
臣服心动
臣服心动 2021-01-13 14:42

I have a java maven project. i have placed a properties file in src/main/resources folder.

src/main/resources
  |
  |___properties
        |
            


        
相关标签:
2条回答
  • 2021-01-13 14:59

    Read the property file from classpath

    Properties prop = new Properties();
    
    try {
        //load a properties file from class path, inside static method
        prop.load(App.class.getClassLoader().getResourceAsStream("config.properties"));            
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    
    0 讨论(0)
  • 2021-01-13 15:02

    Get rid of the "classpath" prefix.: .getBundle("/properties/custom")

    The "classpath" prefix is not a standard, it is defined by some frameworks like spring.

    0 讨论(0)
提交回复
热议问题