Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I would like to control the settings in web.xml and using different once for different environments.

Is it possible to use a property, from a property file on classpath, in web.xml? Something like this:

 <context-param>
  <param-name>myparam</param-name>
  <param-value>classpath:mypropertyfile.properties['myproperty']</param-value>
 </context-param>

Best regards

P

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
807 views
Welcome To Ask or Share your Answers For Others

1 Answer

No. However you can pass the properties file in and read from it at runtime.

<context-param>
    <param-name>propfile</param-name>
    <param-value>myprop.properties</param-value>
</context-param>

It is then trivial to load the property at runtime if you have access to the servlet.

Properties properties = new Properties();
GenericServlet theServlet = ...;
String propertyFileName = theServlet.getInitParameter("propfile");
properties.load(getClass().getClassLoader().getResourceAsStream(propertyFileName));
Object myProperty = properties.get("myProperty");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...