Manuel Pap
Manuel Pap

Reputation: 1389

Spring Boot doesnt bind to Tomcat port

I am trying to deploy a war Spring Boot project into a Tomcat server that has other projects bound to some ports. When I am deploying the new war project, the services don't seem to be bound to the port 8082 that has been assigned from Spring Boot application-properties.

First of all, I added the new port 8082 on 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

Then with netstat -plnt I saw the port is available

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

By going to /opt/apache-tomcat-7.0.88/webapps it seems that my new war application has been deployed.

Application Logs doesn't show any errors or exceptions and the Spring Boot application seems to run. Here are the full logs from Spring: https://pastebin.com/nX04gjE3

When I am trying to test the services with

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

I get the following

--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.

After every change, I restart apache of course. This is a deployed server and not on the local machine, every change I made is with putty and 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

Edit: I don't need the app to run on 8082 I can accept answers for the same port for the others 8080.

Upvotes: 3

Views: 1633

Answers (1)

Maciej Kowalski
Maciej Kowalski

Reputation: 26492

You would need to specify a new section in the server.xml just for that app if you want to run it under a specific port apart from another being also available:

 <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 wise, make sure your normal Main class extends:

@SpringBootApplication
public class App extends SpringBootServletInitializer

Upvotes: 1

Related Questions