简体   繁体   English

Spring Boot + Tomcat 忽略 server.port 属性?

[英]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.我目前正在尝试通过一些小的配置更改来启动和运行 Spring Boot 应用程序,但我似乎无法让端口正确监听。 It seems that the server.xml that the tomcat instance loads overwrites anything my application.properties file specifies. tomcat 实例加载的 server.xml 似乎覆盖了我的 application.properties 文件指定的任何内容。

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.当我将它部署到我的 /usr/local/tomcat/webapps 时,我可以访问服务器,但只能在端口 8080 上。它似乎忽略了 server.port 属性。 I believe that the server is picking up the properties file correctly since the logging correctly goes to /tmp/my-server.log我相信服务器正在正确获取属性文件,因为日志记录正确转到 /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.最终目标是让服务器在 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 OSX Yosemite、Tomcat 8.0.24、Spring Boot v1.2.4

Spring Boot properties like server.port will only take effect if you use the embedded Tomcat.只有在使用嵌入式 Tomcat 时,Spring Boot 属性(如server.port才会生效。 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 .也就是说,如果您通过在其中执行带有SpringApplication.run() main方法或通过创建一个可执行 JAR 并使用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.当您将应用程序作为 WAR 存档部署到独立的 Tomcat 中时,您必须以传统方式通过编辑server.xml和其他可能的配置文件来配置 Tomcat。

server.port property is meant to be used only with an embedded application server. server.port属性仅用于嵌入式应用程序服务器。 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.在 tomcat 的情况下,如果在 server.xml 文件中指定。

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.如果您想在 AWS Elastic Beanstalk 上运行应用程序,则在创建环境时您可以指定您想要一个 webserver + tomcat。

This way you won't need to worry about ports.这样你就不用担心端口了。 Amazon will handle it for you.亚马逊会为您处理。

It is possible toedit the port in the configuration file :可以在配置文件中编辑端口

  1. locate {Tomcat installation folder}\\conf\\server.xml找到{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" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM