I am trying to load a configuration file located in the WEB-INF folder of the application using Spring.
I tried to use
private @Autowired ServletContext servletContext;
and then
servletContext.getResourceAsStream("/WEB-INF/" + fileNm);
But servletContext returns as null.
What am I doing wrong?
My methods are as follows
public static SqlSessionFactory getSqlSessionFactory() { SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(myConnObj.getIpStream("mybatis-config.xml")); } private InputStream getIpStream(String fileNm){ InputStream inputStream = null; try{ inputStream = servletContext.getResourceAsStream("/WEB-INF/" + fileNm); } catch(Exception ex) { ex.printStackTrace(); } return inputStream; }
Vivek source share