[英]Substitute web.xml variables at startup
I have a web.xml file that constains variables in context-param and init-param of filters. 我有一个web.xml文件,它在context-param和过滤器的init-param中构造变量。 I want to replace this variable with values taken from a properties file at application's startup.
我想用应用程序启动时从属性文件中获取的值替换此变量。
My web.xml is like that: 我的web.xml是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<display-name>APP NAME</display-name>
<description>
App description
</description>
<context-param>
<param-name>my-param-name</param-name>
<param-value>${my-param-name}</param-value>
</context-param>
<filter>
<filter-name>Authentication Filter</filter-name>
<filter-class>my.app.Filter</filter-class>
<init-param>
<param-name>filter-var-name</param-name>
<param-value>${filter-var-value}</param-value>
</init-param>
</filter>
...
</web-app>
And the web.properties 和web.properties
my-param-name=${PARAM_VALUE_TO_BE_SETTED_BY_TOOL}
filter-var-value=${FILTER_VALUE_TO_BE_SETTED_BY_TOOL}
Here is how the deployment works: 以下是部署的工作原理:
1) A deployment tool read a given properties file and replace variables with PROD or Dev values (values setted in that tool) and push the file to application module under a JBoss; 1)部署工具读取给定的属性文件,并用PROD或Dev值(在该工具中设置的值)替换变量,并将文件推送到JBoss下的应用程序模块;
2) Start application's deployment on a JBoss. 2)在JBoss上启动应用程序的部署。 I want that web.xml variables be substituted by properties file values on startup.
我希望在启动时将web.xml变量替换为属性文件值。
Thanks in advance. 提前致谢。
We have created a wrapped filter that extends Servlet Filter to set values to web.xml filters variables. 我们创建了一个包装过滤器,它扩展了Servlet过滤器以将值设置为web.xml过滤器变量。 These values are taken from an external properties file for DEV and PROD envirnments.
这些值取自DEV和PROD环境的外部属性文件。
Web.xml: web.xml中:
...
<filter>
<filter-name>CAS Authentication Filter</filter-name>
<filter-class>my.package.WrappedFilter</filter-class>
<init-param>
<param-name>key</param-name>
<param-value>wrappedCasFilter</param-value>
</init-param>
<init-param>
<param-name>class</param-name>
<param-value>org.jasig.cas.client.authentication.AuthenticationFilter</param-value>
</init-param>
</filter>
...
Properties file: 属性文件:
wrappedCasFilter.init.casServerLoginUrl = https://URL
I am sad that I cant't show you the WrappedFilter content. 我很难过,我无法向你展示WrappedFilter的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.