0

I configure connection to database with class DAOProperties.java:

public class DAOProperties {
    private static final String PROPERTIES_FILE = "web/WEB-INF/dao.properties";
    private static final Properties PROPERTIES = new Properties();

    static {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        InputStream propertiesFile = classLoader.getResourceAsStream(PROPERTIES_FILE);

        if(propertiesFile == null) {
            throw new DAOConfigurationException("Properties file '" + PROPERTIES_FILE + "' is missing in classpath.");
        }

        try {
            PROPERTIES.load(propertiesFile);
        } catch (IOException e) {
            throw new DAOConfigurationException(
                    "Cannot load properties file '" + PROPERTIES_FILE + "'.", e);
        }
    }

But when I run my app on localhost tomcat show me error HTTP Status 500 with root cause:

dao.DAOConfigurationException: Properties file 'web/WEB-INF/classes/dao.properties' is missing in classpath. 
...

I tried to change location of my properties file but it didn't help. How to solve this problem?

coi175
  • 39
  • 1
  • 5
  • Does this answer your question? [Tomcat 7 to 8.5 upgrade : getResourceAsStream throws NPE](https://stackoverflow.com/questions/66461262/tomcat-7-to-8-5-upgrade-getresourceasstream-throws-npe) – Piotr P. Karwasz Mar 08 '21 at 09:46
  • 1
    The code you published is inconsistent with the error message you provided (in the code there is no `classes`). If the file **is** in `WEB-INF/classes/dao.properties` (relative to the web application root), you should use `getResourceAsStream("/dao.properties")`. – Piotr P. Karwasz Mar 08 '21 at 09:48

0 Answers0