Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot + Tomcat ignoring server.port property?

I'm currently trying to get a Spring Boot application up and running with some small configuration changes, but I can't seem to get the port to listen correctly. It seems that the server.xml that the tomcat instance loads overwrites anything my application.properties file specifies.

application.properties:

logging.level.app = TRACE
logging.file = /tmp/my-server.log
server.port = 8081

When I deploy this to my /usr/local/tomcat/webapps, I can access the server, but only on port 8080. It seems to ignore the server.port property. I believe that the server is picking up the properties file correctly since the logging correctly goes to /tmp/my-server.log

The end goal is to have the server listen on the port of my choice when running in Amazon Elastic Beanstalk. I can update the ports on the load balancer, but if the server will only listen on it's pre-configured port, that won't matter.

Thanks ahead of time for any help!

OSX Yosemite, Tomcat 8.0.24, Spring Boot v1.2.4

like image 237
Brian Avatar asked Jul 23 '15 15:07

Brian


3 Answers

Spring Boot properties like server.port will only take effect if you use the embedded Tomcat. That is, if you start your application by executing your main method with SpringApplication.run() in it or by creating an executable JAR and starting it with java -jar.

When you deploy your application as a WAR archive into a stand-alone Tomcat, you have to configure Tomcat in the traditional way by editing server.xml and possibly other configuration files.

like image 83
hzpz Avatar answered Sep 27 '22 22:09

hzpz


server.port property is meant to be used only with an embedded application server. If you want to use a standalone one, then the configuration needs to be done on application server itself. In case of tomcat, if is specified in server.xml file.

If you want to run the application on AWS Elastic Beanstalk, when you are creating the environment you can specify that you want to have an webserver + tomcat.

This way you won't need to worry about ports. Amazon will handle it for you.

like image 38
Paulo Santos Avatar answered Sep 27 '22 22:09

Paulo Santos


It is possible to edit the port in the configuration file:

  1. locate {Tomcat installation folder}\conf\server.xml
  2. Find a statement similar to the following:
    <!-- Define a non-SSL HTTP/1.1 Connector on port 8180 -->
       <Connector port="8080" maxHttpHeaderSize="8192"
                  maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
                  enableLookups="false" redirectPort="8443" acceptCount="100"
                  connectionTimeout="20000" disableUploadTimeout="true" />
    
    or
    <Connector port="8080" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" />
    
  3. Change the port number:
    <Connector port="8181" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" />
    
like image 35
SadException Avatar answered Sep 27 '22 22:09

SadException