0

I have a spring boot application which is a cron job that runs daily. I recently migrated my spring boot application to 2.1.6 from 1.5.10 and Java from 8 to 11. When deployed in the server this app is throwing an Exception: java.net.BindException: Address already in use

It was working fine on the lower version.

I made sure there is no other services running on the port 8590.

Below is my gradle file:

plugins {
    id 'org.springframework.boot' version '2.1.6.RELEASE'
    id 'java'
}

apply plugin: 'io.spring.dependency-management'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'jacoco'
apply plugin: 'checkstyle'
apply plugin: 'jdepend'

sourceCompatibility = 1.11

bootJar {
    baseName = 'alerts-service'
}

checkstyle {
    ignoreFailures = true
    toolVersion = '8.2'
    configDir = file("$rootProject.projectDir/etc/checkstyle")
    System.setProperty('checkstyle.cache.file', String.format('%s/%s', buildDir, 'checkstyle.cachefile'))
}

repositories {
    maven {
        url "http://repo/repository/cmp-maven-releases"
    }
    maven {
        url "http://repo/repository/cmp-maven-snapshots"
    }
    mavenCentral()
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-jdbc') {
        exclude group: 'org.apache.tomcat', module: 'tomcat-jdbc'
    }
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.springframework.boot:spring-boot-starter-mail')

    compile("org.apache.axis:axis:1.4")
    compile('org.apache.commons:commons-lang3:3.5')
    compile('org.apache.httpcomponents:httpclient:4.3.4')
    compile('org.apache.pdfbox:pdfbox:2.0.1')

    compile("com.itextpdf:itextpdf:5.1.3")
    compile("com.itextpdf:itext-xtra:5.1.3")
    compile("com.itextpdf.tool:xmlworker:1.1.1")

    compile("net.sf.ehcache:ehcache:2.10.3")

    compile("commons-discovery:commons-discovery:0.5")
    compile("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.8.4")

    compile('ch.qos.logback:logback-core:1.1.8')
    compile('ch.qos.logback:logback-classic:1.1.8')
    compile("wsdl4j:wsdl4j:1.6.2")

    compile("javax.jms:jms:1.1")
    compile("com.ibm:mq-mqjms:7.0.1")
    compile('org.springframework:spring-jms:4.3.3.RELEASE')
    runtime("com.ibm:mq-commonservices:7.0.1")
    runtime("com.ibm:mq-headers:7.0.1")
    runtime("com.ibm:mq:7.0.1")
    runtime("com.ibm:mq-jmqi:7.0.1")
    runtime("com.ibm:mq-pcf:7.0.1")
    runtime("net.sf.jt400:jt400-full:5.4")
    runtime("com.ibm:mq-mqcontext:7.0.1")
    runtime("com.ibm:mq-dhbcore:7.0.1")
    runtime("javax.transaction:jta:1.1")

    runtime('com.microsoft:sqljdbc4:4.0')

    testRuntime('com.h2database:h2')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile group: 'junit', name: 'junit', version: '4.4'
}

I have the port specified in my application.properties

server.port=8590

I tried with the below property as well that did not work

management.server.port=8590

management.endpoints.web.exposure.include=*
management.endpoint.shutdown.enabled=true
endpoints.shutdown.enabled=true

Any hints would be greatly appreciated.

EDIT : I tried killing the PID of this service and triggered startup script. I did work and for the next execution it thrown the same error again.

Looks like somehow shutdown has to happen after each execution.

srartup.sh

nohup /opt/jdk-11.0.2/bin/java -Xmx768m -Xms256m -Dlogging.config=/opt/runnables/alerts-service/logback.xml -jar /opt/runnables/alerts-service/alerts-service.jar --spring.profiles.active=qa &> logs/console.log&
user3919727
  • 159
  • 3
  • 14

2 Answers2

0

Check which process is using the port,

In windows

netstat -ano | find "8080"

In linux

netstat -nap | grep 8080

If someone else is using that port, you have to use another port or kill that other process and let the port free.

prime
  • 11,246
  • 11
  • 75
  • 112
0

Finally I found the solution. By adding the application context closing tag has worked for me in main class.

SpringApplication.run(AlertsApplication.class, args).close();
user3919727
  • 159
  • 3
  • 14