7
votes

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

3
Shouldn't these values be configured in tomcat??? I think so.We are Borg
It seems not...after reading: stackoverflow.com/questions/21083170/… docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/… it seems the port is not configured in tomcat?Brian
Or perhaps all that is only for embedded tomcat?Brian
If u have standalone tomcat...go in the directory...go in conf...go in server.xml...there u will see connectors...edit the port number for one with http1.1......if u have spring security...u can specify ports too...but thats for another time.We are Borg

3 Answers

10
votes

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.

0
votes

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.

0
votes

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" />