per*_*son 9 web.xml web-applications properties
我想控制web.xml中的设置,并为不同的环境使用不同的设置.
是否可以在web.xml中使用类路径上的属性文件中的属性?像这样的东西:
<context-param>
<param-name>myparam</param-name>
<param-value>classpath:mypropertyfile.properties['myproperty']</param-value>
</context-param>
Run Code Online (Sandbox Code Playgroud)
最好的祝福
P
不可以.但是,您可以在运行时传递属性文件并从中读取.
<context-param>
<param-name>propfile</param-name>
<param-value>myprop.properties</param-value>
</context-param>
Run Code Online (Sandbox Code Playgroud)
如果您有权访问servlet,那么在运行时加载属性是微不足道的.
Properties properties = new Properties();
GenericServlet theServlet = ...;
String propertyFileName = theServlet.getInitParameter("propfile");
properties.load(getClass().getClassLoader().getResourceAsStream(propertyFileName));
Object myProperty = properties.get("myProperty");
Run Code Online (Sandbox Code Playgroud)