获取端口号码& Tomcat服务器上Spring应用程序中的主机名 [英] Get Port Number & Host Name in a Spring Application on Tomcat Server

查看:411
本文介绍了获取端口号码& Tomcat服务器上Spring应用程序中的主机名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序是部署在 Apache tomcat 6 上的基于Spring框架3.1.2 的Web应用程序。

My application is an Spring framework 3.1.2 based Web-application deployed on Apache tomcat 6.

我需要在应用程序(服务器)启动时运行正在运行的应用程序 port-number host-name 。因此我会在属性上覆盖它,并且需要进行其他bean初始化。

I need to get my running application port-number and host-name on application(server) Start-up. So that I would override it on a property and it is need for Other bean initialization.

Spring是否提供任何选项来检索这些详细信息并在Server Startup上进行设置?..

Does the spring provides any options to retrieves these details and to set it on Server Startup?..

推荐答案

看看之前提出的两个问题:从tomcat获取服务器端口号而没有请求我需要知道我的java webapp在webapp启动时运行的HTTP和HTTPS端口。在那里,您将看到如何从连接器获取端口,连接器还具有可为您提供主机名的getDomain方法。

Take a look into those two questions previously asked: Get the server port number from tomcat with out a request and I need to know the HTTP and HTTPS port my java webapp is running on webapp startup. There you will see how to get port from a Connector, connector also has getDomain method that would give you host name.

由于你知道如何在没有spring的情况下获得,你可以拥有一个获取这些细节的bean,并为需要这些实例化细节的其他bean提供它们。有几种方法可以做到这一点:

Since you know how to get without spring, you can have a bean that gets those details and provides them for the other bean that needs those instantiation detail. There are few ways to do that:

1)创建Spring工厂bean,它将获得你想要的端口,主机名和实例化bean

1) Create Spring factory bean that would get port, hostname and instantiates bean you want

2)有单独的bean为你保存这些细节你使用那个bean来构建另一个

2) Have separate bean that holds those details for you and you use that bean to construct other one

3)你用port替换你的应用程序细节域和实例化需要它们的bean有一个init方法,可以为你的新bean读取它们

3) You override your application details with port and domain and when instantiating bean that needs them have a init method that would read them for your new bean

这篇关于获取端口号码& Tomcat服务器上Spring应用程序中的主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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