My JSP pages need to display different information depending on which environment they\'re in (dev, production, sandbox, etc). I want to have a properties file for each of
You can load the properties using java.util.Properties
(or commons-configuration) in a ServletContextListener
's contextInitialized(..)
method.
register the listener with
in web.xml
You then store the Properties
into the ServletContext
(you can get it from the event) (ctx.setAttribute("properties", properties)
then access the properties using ${applicationScope.properties.propName}
(as BalusC noted, applicationScope
is optional)
Update:
Initially I thought spring had some ready-to-use facility for that, but it turns out it's not exactly the case. You have two options:
this article explains something similar to my suggestion above, but using spring's PropertyPlaceholderConfigurer
this answer and this answer allow you to expose all your beans, including a PropertyPlaceholderConfigurer
to the servlet context.