I am trying to get hold of a file ( or a directory ) under /WEB-INF/.../
outside of a request. I need it in a bean loaded at server startup.
A
Not completely related to your question, but...
Here is some universal sulution i used to load properties from anywhere in web application like Spring does it (supporting WEB-INF/..., classpath:..., file:...). Is is based on using ServletContextResourcePatternResolver. You will need ServletContext.
private static Properties loadPropsTheSpringWay(ServletContext ctx, String propsPath) throws IOException {
PropertiesFactoryBean springProps = new PropertiesFactoryBean();
ResourcePatternResolver resolver = new ServletContextResourcePatternResolver(ctx);
springProps.setLocation(resolver.getResource(propsPath));
springProps.afterPropertiesSet();
return springProps.getObject();
}
I used the above method in my custom servlet context listener while conext was not yet loaded.