@@ -158,6 +158,8 @@ public class Tomcat {
158
158
private final Map <String , List <String >> userRoles = new HashMap <>();
159
159
private final Map <String , Principal > userPrincipals = new HashMap <>();
160
160
161
+ private boolean addDefaultWebXmlToWebapp = true ;
162
+
161
163
public Tomcat () {
162
164
ExceptionUtils .preload ();
163
165
}
@@ -623,12 +625,15 @@ public Context addWebapp(Host host, String contextPath, String docBase,
623
625
Context ctx = createContext (host , contextPath );
624
626
ctx .setPath (contextPath );
625
627
ctx .setDocBase (docBase );
626
- ctx .addLifecycleListener (getDefaultWebXmlListener ());
628
+
629
+ if (addDefaultWebXmlToWebapp )
630
+ ctx .addLifecycleListener (getDefaultWebXmlListener ());
631
+
627
632
ctx .setConfigFile (getWebappConfigFile (docBase , contextPath ));
628
633
629
634
ctx .addLifecycleListener (config );
630
635
631
- if (config instanceof ContextConfig ) {
636
+ if (addDefaultWebXmlToWebapp && ( config instanceof ContextConfig ) ) {
632
637
// prevent it from looking ( if it finds one - it'll have dup error )
633
638
((ContextConfig ) config ).setDefaultWebXml (noDefaultWebXmlPath ());
634
639
}
@@ -803,6 +808,24 @@ private void silence(Host host, String contextPath) {
803
808
}
804
809
805
810
811
+ /**
812
+ * By default, when calling addWebapp() to create a Context, the settings from
813
+ * from the default web.xml are added to the context. Calling this method with
814
+ * a <code>false</code> value prior to calling addWebapp() allows to opt out of
815
+ * the default settings. In that event you will need to add the configurations
816
+ * yourself, either programmatically or by using web.xml deployment descriptors.
817
+ * @param addDefaultWebXmlToWebapp <code>false</code> will prevent the class from
818
+ * automatically adding the default settings when
819
+ * calling addWebapp().
820
+ * <code>true</code> will add the default settings
821
+ * and is the default behavior.
822
+ * @see #addWebapp(Host, String, String, LifecycleListener)
823
+ */
824
+ public void setAddDefaultWebXmlToWebapp (boolean addDefaultWebXmlToWebapp ){
825
+ this .addDefaultWebXmlToWebapp = addDefaultWebXmlToWebapp ;
826
+ }
827
+
828
+
806
829
/*
807
830
* Uses essentially the same logic as {@link ContainerBase#logName()}.
808
831
*/
0 commit comments