-1

The method works properly without path variable but then when I write path variable and run app it says port 8080 is already in use

@GetMapping(path="/{userId}")
public String getUser(@PathVariable String userId) {
    return "Get User Info with id "+userId;
}
Ivana
  • 29
  • 1
  • 6
  • 3
    It has nothing to do with the @PathVariable. This says that you already have a process running on the same port. My guess is that you try running a new one and the old one is still running – grekier Aug 04 '21 at 15:12
  • What is the operation system? depends your OS, you need to understand which app holds this port, if it a different app from your app you can change the 8080 in springboot application.properties [server.port=XXXX]. In case your springboot app already holds it you should kill the process from IDE or command line. – 4EACH Aug 04 '21 at 15:25
  • Possible duplicate https://stackoverflow.com/questions/34253779/tomcat-server-error-port-8080-already-in-use – 4EACH Aug 04 '21 at 15:32

4 Answers4

4

First your issue is not with Path variable, Port 8080 is been used by some other application

Command for Linux,

sudo netstat -nlap | grep 8080
sudo kill <process id>

Command for Windows

netstat -ano | findstr :8080
taskkill /PID <process id> /F

If any application uses the port 8080, it will return the process id.

Dev
  • 92
  • 7
3

On mac, try this

sudo lsof -i :8080

# get the process id from here and run

kill -9 <process_id>
Michael Scott
  • 540
  • 2
  • 8
1

I solved it, on Windows

netstat ano | findstr 8080 

taskkill /F /PID <number of task>

Ivana
  • 29
  • 1
  • 6
0

To get rid from Port was already in use just put server.port=0 in yml or properties file ,it will auto generate port number for application.