Search code examples
springwarweb-inf

unable to access the property file when deployed on Apache Tomcat


I have used my user.properties file to access the database which is stored in the WEB-INF folder. Its working properly while running through GGTS(Groovy Grail Tool Suite).

I used

Properties prop = new Properties();
prop.load(DataSource.class.getClassLoader().getResourceAsStream("user.properties"));

in DataSource

Its working when i run it as standalone

But when i create its war file and deploy it onto the tomcat server its not working.

My user.properties is in the WEB-INF folder.

Showing error

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pluginManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException

Thanks in adavance. Please Help


Solution

  • You're loading the file using the class loader. But WEB-INF is not in the classpath. WEB-INF/classes is in the classpath, as well as every jar in the WEB-INF/lib directory.