Issue
I have a Spring Boot application. I want to display the current Servlet Container name and version in an Admin Console page.
Currently my application uses Tomcat, but I want to automatically display the same information if I were to, say, change to Jetty or some other embedded servlet container.
This information is not available (at least it seems) through the Environment
, or Actuator
endpoints.
How can I programmatically obtain the embedded servlet container name and version?
Solution
You can get the information you are looking for from the ServletContext
.
You can autowire it with:
@Autowired ServletContext context;
and then access the wanted information:
context.getServerInfo()
In my Spring Boot application with an embedded Tomcat, I obtain the following string:
Apache Tomcat/8.5.27
Answered By - Ortomala Lokni
Answer Checked By - Mildred Charles (JavaFixing Admin)