简体   繁体   中英

Substitute web.xml variables at startup

I have a web.xml file that constains variables in context-param and init-param of filters. I want to replace this variable with values taken from a properties file at application's startup.

My web.xml is like that:

<?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

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;

2) Start application's deployment on a JBoss. I want that web.xml variables be substituted by properties file values on startup.

Thanks in advance.

We have created a wrapped filter that extends Servlet Filter to set values to web.xml filters variables. These values are taken from an external properties file for DEV and PROD envirnments.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM