Grails:WAR文件部署:查找端口 [英] Grails: WAR file deployment : Finding the port

查看:58
本文介绍了Grails:WAR文件部署:查找端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Grails 2.3.6应用程序,在服务器中作为WAR文件运行.目前,它正在Tomcat 7中运行.

I have a Grails 2.3.6 app running as a WAR file in a server. Currently it's running in Tomcat 7.

将来我们可能还会在其他服务器上运行该应用程序.

In future we might have the app run in other servers too.

现在我面临的问题是独一无二的.在服务常规文件之一中,我需要获取正在运行的应用程序的端口号.

Now the problem i face is unique. In one of the service groovy files i need to get the port number for the running app.

对于Tomcat,端口号是在 server.xml 中设置的,一种可能的获取方法是从那里读取.

For Tomcat the port number is set in server.xml and one potential way to get that will be to read from there.

但是我正在寻找更通用的解决方案.这样,即使将WAR文件部署在其他类型的服务器中,我也可以获取端口号.

But am looking for a more generic solution. So that even if the WAR file is deployed in other type of servers, i could get the port number.

欢迎提出任何建议!

推荐答案

端口(单数)不一定定义明确,例如您可以为Tomcat配置多个侦听不同端口的连接器,或者同时提供http和https.在特定请求的上下文中,您可以谈论接收到该请求的端口",但是如果您的应用程序位于反向代理或负载平衡器的后面,会发生什么……

The port (singular) isn't necessarily well-defined, e.g. you can have a Tomcat configured with several connectors listening on different ports, or serving both http and https. In the context of a particular request you can talk about "the port" that that request was received on, but then what happens if your app is behind a reverse proxy or load balancer...

唯一可靠的方法是在配置文件中手动指定适当的端口号/URL/任何名称(例如,外部的 grails.config.locations ).

The only reliable approach is to manually specify the appropriate port number/URL/whatever in a configuration file (e.g. a grails.config.locations external).

这篇关于Grails:WAR文件部署:查找端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆