Summary: | Tomcat Embedded: using tomcat.addWebapp always overrides programmatic context-settings with default values for the context at start of tomcat server | ||
---|---|---|---|
Product: | Tomcat 7 | Reporter: | bhuber <berndhuber98> |
Component: | Catalina | Assignee: | Tomcat Developers Mailing List <dev> |
Status: | RESOLVED FIXED | ||
Severity: | normal | ||
Priority: | P2 | ||
Version: | 7.0.16 | ||
Target Milestone: | --- | ||
Hardware: | PC | ||
OS: | Linux | ||
Attachments: | Attached patch that only sets StandardManager if the manager is not already set |
Description
bhuber
2011-07-26 10:11:48 UTC
Use addContext() (In reply to comment #1) > Use addContext() because i need to deploy a WAR-File, that includes a web.xml file, it would be more complicated to use addContext(), because i cant find any examples in the web that use addContext() in combination with web.xml... but your right, this should be a missing feature, not a bug. I hope some official documentation for tomcat-embedded will be available soon. ah sorry, its ok nevermind .. i know now how to do it: ;-) like you said, i will now just create a standardcontext instead, and just dont add a defaultwebxmllistener ... Context ctx = new StandardContext(); ctx.setName(name); ctx.setPath(url); ctx.setDocBase(path); if (defaultRealm == null) { initSimpleAuth(); } ctx.setRealm(defaultRealm); ContextConfig ctxCfg = new ContextConfig(); ctx.addLifecycleListener(ctxCfg); // prevent it from looking ( if it finds one - it'll have dup error ) ctxCfg.setDefaultWebXml("org/apache/catalin/startup/NO_DEFAULT_XML"); if (host == null) { getHost().addChild(ctx); } else { host.addChild(ctx); } A user of memcached-session-manager also ran into this issue and it took me some time that when using addWebapp the manager is just overwritten. I'd suggest to set the StandardManager only if there's no manager set on the context. Are there any problems why this should not be done? Created attachment 27432 [details]
Attached patch that only sets StandardManager if the manager is not already set
StandardContext already conditionally adds a StandardManager if one is not set. Since the offending code is meant to be replicating conf/web.xml (which can't set internal Tomcat components) I have simply removed this code from the listener. The fix has been applied to trunk and 7.0.x and will be included in 7.0.21 onwards. |