3

I want to be able to deploy a .war file and detect which port the application is being served on. I have two grails' apps running within different tomcat instances, and ideally I would like to adapt the configuration of each app according to each specific tomcat instance. Each tomcat instance uses a different port, therefore detecting the port upon which the app is served means the app knows which tomcat instance the app is running in.

Thanks for any help!

4

2 回答 2

1

我使用了一个外部化配置,以便两个 grails 应用程序都可以读取与每个相应的 tomcat 实例启动位置相关的配置。通过控制每个 tomcat 实例的启动位置,可以适当地配置每个 grails 应用程序。因此,通过将外部配置相对于启动tomcat目录放置特定grail的应用程序配置来实现!

于 2012-09-17T08:59:26.107 回答
0

第一个请求到达时获取端口是否足够?那么这可能会有所帮助:

    println request.requestURL
    println request.request.request.request.connector.port

如果没有,请查看这些页面 - 我想它们可能会有所帮助

无需请求即可从 tomcat 获取服务器端口号

http://www.asjava.com/tomcat/how-to-get-tomcat-port-number-in-java/

永远记住,oyu 可以在您的 grails 应用程序中使用所有可用的 java 代码。

于 2012-09-09T19:27:10.670 回答