I would like to specify the root context of my Java web application in my WAR file. How can I do this using valid web-app
XML in a web.xml
file?
Oh, yes I would like to do this in an application server agnostic way.
root-context. xml is the Spring Root Application Context Configuration. It's optional. It's for configuring your non-web beans.
The root element of a web. xml is web-app .
To change the context root of a web application that is already available in the Eclipse workspace, simply right-click on the web project and call the “Properties” action from the context menu.
All you need to do is to declare the ContextLoaderListener in your web. xml and use a contextConfigLocation to set which context files to load. You can then use the WebApplicationContext to get a handle on your beans. Here is the link for latest APIs related to WebApplicationContextUtils.
This can't be done in an appserver agnostic way. Context root isn't part of the standard web.xml file. It's either specified when you deploy the app or in an appserver specific descriptor.
Note: the above applies to deploying WAR files. EAR files are a different story and the context can be specified as part of the application.xml deployment descriptor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With