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?
Since the servlet 3 specification (IIRC) a web. xml is not needed anymore.
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!
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.
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