Search code examples
springport

problem 8080 already listening java spring


my port 8080 in java Spring so never disconnects. The process remains open even if I stop the application. Which means that when I launch the project and restart it a second time after a code modification, I am shown that it is already listening. It's the same project. I therefore have to go to currport to stop the process each time a line of code changes if I restart the project. If I change the port in application.properties, all the ports that I indicate are displayed "already listening" while ultimately, currport does not find any process on these ports. So I waste a lot of time killing the 8080 process on currport between each launch OF THE SAME PROJECT, something I never did before, I have java on 2 other PCs and it doesn't do that, I can re-run a project without kill the process. When I launch my project, it listens on one port, as long as I don't stop it, whether I launch my project 1 time or 10 times, the listening is the same. I don't know what change there was, but it affects all my spring projects only on the 8080, all other projects which launch a web service on another port do not have this problem. I've never had this problem before.

2024-04-13T15:03:49.253+02:00  INFO 4584 --- [  restartedMain] com.example.calcul.CalculApplication     : Starting CalculApplication using Java 21.0.2 with PID 4584 (C:\Users\chres\Documents\jetBrainProjects\intellij-idea-projects\calcul\target\classes started by chres in C:\Users\chres\Documents\jetBrainProjects\intellij-idea-projects\calcul)
2024-04-13T15:03:49.256+02:00  INFO 4584 --- [  restartedMain] com.example.calcul.CalculApplication     : No active profile set, falling back to 1 default profile: "default"
2024-04-13T15:03:49.314+02:00  INFO 4584 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2024-04-13T15:03:49.315+02:00  INFO 4584 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2024-04-13T15:03:50.575+02:00  INFO 4584 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port 8080 (http)
2024-04-13T15:03:50.587+02:00  INFO 4584 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2024-04-13T15:03:50.588+02:00  INFO 4584 --- [  restartedMain] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.19]
2024-04-13T15:03:50.637+02:00  INFO 4584 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2024-04-13T15:03:50.639+02:00  INFO 4584 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1322 ms
2024-04-13T15:03:51.267+02:00  WARN 4584 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : Unable to start LiveReload server
2024-04-13T15:03:51.288+02:00  WARN 4584 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'
2024-04-13T15:03:51.302+02:00  INFO 4584 --- [  restartedMain] .s.b.a.l.ConditionEvaluationReportLogger : 

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2024-04-13T15:03:51.323+02:00 ERROR 4584 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

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

Action:

Identify and stop the process that's listening on port 8080 or configure this application to listen on another port.

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.912 s
[INFO] Finished at: 2024-04-13T15:03:51+02:00
[INFO] ------------------------------------------------------------------------

Process finished with exit code 0

even if I change the port in application.properties, it gives me the same problem, all the ports that I put are already listening while no process with these ports exists.

it is not another process which can be incriminated, because when I stop the process on port 8080 via currport, my project runs again, but I restart it just after, it gives me an error again because port busy, so before restarting my project which is already listening, I have to stop the process manually, can you imagine doing this every time you modify your code?

pressing the red button to stop the process has no effect. thanks


Solution

  • To solve this first you need to open your Command Line (cmd) and type:

    netstat -ano | findstr :8080

    This will identify the process ID that is using the 8080 port,

    Then on the same comand line type the following command:

    taskkill /PID yourProcessNumber /F

    Where yourProcessNumber must be replaced by the process number you just identified previously.

    I hope this helps

    The number 31420 would be the process id number in my case [1]: https://i.sstatic.net/939uM.png