Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify display name for web app configured without web.xml

How to specify display name for web application (war) configured programmatically in java with WebApplicationInitializer only. I have something like this

public class WebAppInitializer implements WebApplicationInitializer {
  public void onStartup(ServletContext servletContext) throws ServletException {
     ...
  }
}

With web.xml this look like this:

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="3.0" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"    metadata-complete="false">
   <display-name>my app</display-name>
   ...
</web-app>

Is this possible in Java configuration?

like image 202
MariuszS Avatar asked Oct 23 '13 18:10

MariuszS


People also ask

Is WEB xml necessary?

Since the servlet 3 specification (IIRC) a web. xml is not needed anymore.

Does spring boot require WEB xml?

Spring Boot takes an opinionated view of the Spring platform and third-party libraries, allowing us to get started with a minimal configuration. For example we can develop a Jave EE based web application without any configuration files. Not even a web. xml file is required!


1 Answers

The ServletContext interface does not provide a method to change the display name. There are some other things that it also doesn't let you do. In those cases, you have to use the deployment descriptor, ie. the web.xml.

Note that it has a getServletContextName() method which

Returns the name of this web application corresponding to this ServletContext as specified in the deployment descriptor for this web application by the display-name element.

like image 62
Sotirios Delimanolis Avatar answered Oct 17 '22 07:10

Sotirios Delimanolis