【问题标题】:Determine App Server type from Spring? [duplicate]从 Spring 确定 App Server 类型? [复制]
【发布时间】:2016-09-06 17:09:58
【问题描述】:

我想打印(作为调试信息)运行我的 webapp 的应用服务器的类型和版本。

到目前为止,我通过org.springframework.core.env.Environment 进行了一些搜索:

this.environment.getProperty("java.naming.factory.initial")

但是它只是说"org.apache.naming.java.javaURLContextFactory" 而不是我想看到的"Apache Tomcat/8.0.33"

【问题讨论】:

  • 您的应用程序是否总是在 Tomcat 上运行而您只想打印其版本?

标签: java spring appserver


【解决方案1】:

使用ServletContext.getServerInfo()

顺便说一句:在 Spring 中你可以注入 ServletContext

@Service
public class ServerLoggingService() {

  @Autowired
  private ServletContext servletContext;

  @PostConstruct
  public void printServer() {
      System.out.println("Server Version: " + this.servletContext.getServerInfo());
  }
}

【讨论】:

  • 在某些地方可以注入 servlet 上下文,但在其他地方则不行。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-18
  • 1970-01-01
  • 2018-02-04
  • 1970-01-01
  • 2019-08-26
  • 2019-06-24
  • 2011-05-24
相关资源
最近更新 更多