I'm using Spring 4.1.1 with pure Java Config (i.e., no web.xml at all). The AnnotationConfigWebApplicationContext has a displayName property, which I assume is analogous to the display-name tag in a web.xml file. However, when I set this property in Java Config, the "Display Name" column in the Tomcat Manager is empty when I deploy the WAR unlike if I would have used the display-name tag in web.xml.
Is this the intended behavior or am I doing something wrong. I'm using the latest version of Tomcat which is 7.0.57, Java 1.7 u51, and Groovy 2.3.7.
@Slf4j
class WebAppInitializer implements WebApplicationInitializer {
{
@Override
void onStartup(ServletContext container) throws ServletException {
def rootContext = new AnnotationConfigWebApplicationContext()
rootContext.register(WebAppConfig)
rootContext.servletContext = container
rootContext.displayName = 'Description of WAR goes here!'
DispatcherServlet dispatcherServlet = new DispatcherServlet(rootContext)
dispatcherServlet.throwExceptionIfNoHandlerFound = true
def dispatcherServletReg = container.addServlet('dispatcher', dispatcherServlet)
dispatcherServletReg.addMapping('/')
dispatcherServletReg.loadOnStartup = 1
}
}
Thanks ahead of time for any help.
Well as you are seeing the displayName being set is just for the Spring ApplicationContext and isn't at all related to the web.xml display-name. The web.xml display-name aligns with: container.getServletContextName();
Since this object is already passed in with its value set and the ServletContext interface doesn't allow you to change this value I'm not sure its possible with a purely java configuration.
You can however still use a partial web.xml in conjunction with the WebApplicationInitializer by setting metadata-complete="false":
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
metadata-complete="false" version="3.0">
<display-name>Web Application Name</display-name>
</web-app>
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