Spring Boot没有绑定到Tomcat端口

时间:2019-06-10 06:54:34

标签: java spring spring-boot tomcat

我正在尝试将war Spring Boot项目部署到Tomcat服务器中,该服务器的其他端口绑定了某些项目。当我部署新的war项目时,服务似乎没有绑定到从Spring Boot 8082分配的端口application-properties上。

首先,我在8082上添加了新端口server.xml

<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="-1"
           redirectPort="8443" /> //That was already specified

<Connector port="8082" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" /> //My addition

然后与netstat -plnt一起看到端口可用

tcp6       0      0 :::8082                 :::*                    LISTEN      -

进入/opt/apache-tomcat-7.0.88/webapps似乎已经部署了新的war应用程序。

应用程序日志未显示任何错误或异常,并且Spring Boot应用程序似乎正在运行。以下是Spring的完整日志:https://pastebin.com/nX04gjE3

当我尝试使用

测试服务时

wget http://localhost:8082/services/test

我得到以下内容

--2019-06-10 09:49:56--  http://localhost:8082/services/test
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:8082... connected.
HTTP request sent, awaiting response... 404 Not Found
2019-06-10 09:49:56 ERROR 404: Not Found.

每次更改后,我当然会重新启动apache。 这是一台已部署的服务器,不在本地计算机上,我所做的每个更改都是使用腻子和winscp进行的。

ServicesApplication.java

@SpringBootApplication
public class ServicesApplication extends SpringBootServletInitializer {


    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(ServicesApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(ServicesApplication.class, args);
    }

}

application-properties

server.port=8082
http.port=8082


logging.file = /opt/logs/services.log


spring.datasource.url=jdbc:mysql://X.X.X.X/name?useSSL=false
spring.datasource.username=username
spring.datasource.password=password
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

编辑:我不需要在8082上运行该应用程序,我可以为其他8080接受同一端口的答案。

1 个答案:

答案 0 :(得分:1)

如果要在特定端口(除了另一个可用端口)上运行该应用,则需要在server.xml中为该应用指定一个新部分:

 <Server>
  <Service name="commonservice">
    <Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="-1"
           redirectPort="8443" />
    <Engine><Host name="commonhost">
          <Context path="/commonwebab"/>     
    </Host></Engine>
  </Service>
  <Service name="springservice">
    <Connector port="8082" protocol="HTTP/1.1"
           connectionTimeout="20000"
       redirectPort="8444" />
    <Engine><Host name="springhost">
      <Context path="/springapp"/>
    </Host></Engine>
  </Service>
</Server>

明智地使用Spring Boot,请确保正常的Main类扩展了:

@SpringBootApplication
public class App extends SpringBootServletInitializer