根据 Spring 确定 App Server 类型?
Determine App Server type from Spring?
我想打印(作为调试信息)我的 webapp 运行 上的 App Server 的类型和版本。
到目前为止,通过一些搜索,我能够通过 org.springframework.core.env.Environment
:
找到这个
this.environment.getProperty("java.naming.factory.initial")
然而它只是说 "org.apache.naming.java.javaURLContextFactory"
而不是我想看到的 "Apache Tomcat/8.0.33"
。
使用ServletContext.getServerInfo()
顺便说一句:在 Spring 中你可以注入 ServletContext
@Service
public class ServerLoggingService() {
@Autowired
private ServletContext servletContext;
@PostConstruct
public void printServer() {
System.out.println("Server Version: " + this.servletContext.getServerInfo());
}
}
我想打印(作为调试信息)我的 webapp 运行 上的 App Server 的类型和版本。
到目前为止,通过一些搜索,我能够通过 org.springframework.core.env.Environment
:
this.environment.getProperty("java.naming.factory.initial")
然而它只是说 "org.apache.naming.java.javaURLContextFactory"
而不是我想看到的 "Apache Tomcat/8.0.33"
。
使用ServletContext.getServerInfo()
顺便说一句:在 Spring 中你可以注入 ServletContext
@Service
public class ServerLoggingService() {
@Autowired
private ServletContext servletContext;
@PostConstruct
public void printServer() {
System.out.println("Server Version: " + this.servletContext.getServerInfo());
}
}