How to configure web.xml configuration

I would like to deploy the same web application to several different clients. Each deployment requires a different value in one of the elements of the web.xml configuration file.

Without creating a different .war file for each client (with different values ​​set in the web.xml file in each .war), is it possible to configure values ​​for different clients? For example, can a web.xml file extract values ​​from a deployment property file?

We use Tomcat as a servlet container.

+3
source share
3 answers

web.xml Tomcat JNDI.

, Context:

<Context ...>
  ...
  <Environment name="maxExemptions" value="10"
         type="java.lang.Integer" override="false"/>
  ...
</Context>

web.xml:

<env-entry>
  <env-entry-name>maxExemptions</param-name>
  <env-entry-type>java.lang.Integer</env-entry-type>
</env-entry>

, ( Professional Apache Tomcat 6):

private final Object lock = new Object();
...
synchronized (lock) {
    Context initCtx = new InitialContext();
    Context envCtx = initCtx.lookup("java:comp/env");
    Integer maxExemptions = (Integer) envCtx.lookup("maxExemptions");
}

Spring <jndi-lookup />

<bean id="someBean">
    <property name="maxExemptions">
        <jndi-lookup jndi-name="xxx" />
    </property>
</bean>
+1

web.xml? , . .

+1

: .

A more complicated version: the war may contain some parameters and default values, which you can often change using the console of the application server or web server. It depends on what you want to configure, are these standard parameters context / servlet / ...?

0
source

Source: https://habr.com/ru/post/1710498/


All Articles