javaspring-bootgradleport

Web server failed to start. Port 8080 was already in use. Spring Boot microservice


I am trying to call webAPI from gradle project.

My build.gradle is as following.

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

apply plugin: 'io.spring.dependency-management'

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    runtimeOnly 'org.springframework.boot:spring-boot-devtools'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    compile 'org.springframework.boot:spring-boot-starter-webflux'
    compile 'org.projectreactor:reactor-spring:1.0.1.RELEASE'
}

If I remove following dependency

compile 'org.springframework.boot:spring-boot-starter-webflux'

It works, but if I add it back. it gives error as

Web server failed to start. Port 8080 was already in use.

So, how do I fix this, so that I can use webclient? Because application is not web application which requires port to run. it is a sort of microservice.

I just want to use WebClient of Spring Boot. How do i use it without converting my application into web application.


Solution

  • If you don't want the embedded server to start, just set the following property in you application.properties (or .yml):

    spring.main.web-application-type=none
    

    If your classpath contains the necessary bits to start a web server, Spring Boot will automatically start it. To disable this behaviour configure the WebApplicationType in your application.properties

    Source: https://docs.spring.io/spring-boot/docs/current/reference/html/howto-embedded-web-servers.html


    If you application really is a Web application, then you can easily change the port using the server.port property (in your application's .properties/.yaml file, as a command line argument at startup, etc).