Reputation: 41
Used to run Spring MVC project is Eclipse Version: 2020-03 (4.15.0) using Tomcat 8.5. When I run the project it displays "port already in use error" in console, but when I run on browser localhost:8080/ it works. But when I look in to the 'Servers' section in Eclipse it stopped but I think it is managed by Spring boot configuration that I included in pom.xml. and there the server is started already in port 8080, correct me if I am wrong there.
I am confused what exactly 'Server' section shows in Eclipse project and how we can change the port to something else from Eclipse, if possible?
could someone help me to understand this by explaining what actually happening in the background ?
bs: there's new server folder created out of the workspace when I add new server.
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Upvotes: 0
Views: 2494
Reputation: 41
Alright, I found the answer after spending time on research and trail & error.Thanks for everyone who contributed to this question, that's what it makes me to spend more time to understand the problem. Since actually I am a beginner on work on creating spring project from scratch. Please bear with me.
Actually I would like to point out these.
1) This project is initialized from https://start.spring.io/, so that means it is spring boot based project, not a plain spring-MVC project(with those .XML files).
2) I have been running it on an embedded Tomcat server where I should follow the practice when I run the application. one approach is ./mvnw spring-boot:run
and another approach is creating a .JAR
file by ./mvnw clean package
and run it.
I did the mistake by attaching the another Tomcat(stand-alone) server when I run the application via Eclipse. So that is wrong.
Here you can see now there is no server displays under 'Server' section in Eclipse but when I run the application it runs successfully (see the console) and listening to default port 8080 also if I want to change the port that is possible by passing as a argument.-Dserver.port=8081
or every other options you guys suggested.
any suggestions for improving this highly appreciated. please vote if you feel good about my findings.
references:
Upvotes: 0
Reputation: 41
I would happy ifsomeone vote up this question, I feel it's a valid question as there are some confusion might raise as many configurations options available like embedded server vs stand alone server, spring boot behaviour when it comes to loading the relevant dependencies to class path.
happy if someone vote this question up, so I keep continue my profile updated.
thanks.
Upvotes: 0
Reputation: 3697
There is a hanging java process that listens on that port.
Find the process by port and kill it.
for linux you can use fuser -k 8080/tcp
for windows netstat -ano | findstr :PORT_NUMBER
to get the PID and then kill it
apart from that you can use JavaVisualVM
to track all java applications running on your machine
Upvotes: 0
Reputation: 20023
Manually going to localhost:8080 works because of the error message. Another process, likely another copy of Tomcat, is already running and listening on that port--it's what is sending a response back to your browser. The right side of the server editor you're showing in the first image has the Ports section visible. That is where you can change the Port numbers for the instance you launch from Eclipse.
Upvotes: 0
Reputation: 2165
Follow the following steps:
-Dserver.port=8081
Instead of 8081
you can put any other port number also.
Upvotes: 2