Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Port Number & Host Name in a Spring Application on Tomcat Server

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

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.

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

like image 900
omega Avatar asked Dec 18 '12 08:12

omega


1 Answers

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.

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) Create Spring factory bean that would get port, hostname and instantiates bean you want

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

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

like image 158
Eds Avatar answered Oct 26 '22 14:10

Eds