运行 本地主机中的 spring boot 应用程序出错

Getting error when run springboot application in local host

当我 运行 本地主机中的应用程序第一次运行时。但是我更改了代码并重新 运行 它显示了此错误消息。当我终止所有进程并重新运行。再次显示下面的消息。


  .   ____          _            __ _ _
 /\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.1)

2021-01-15 13:25:06.321  INFO 7180 --- [           main] com.example.demo.SocialApiApplication    : Starting SocialApiApplication using Java 15.0.1 on DESKTOP-TCH1T7S with PID 7180 (E:\springboot\SocialAPI\target\classes started by Samanthika in E:\springboot\SocialAPI)
2021-01-15 13:25:06.325  INFO 7180 --- [           main] com.example.demo.SocialApiApplication    : No active profile set, falling back to default profiles: default
2021-01-15 13:25:07.193  INFO 7180 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8006 (http)
2021-01-15 13:25:07.205  INFO 7180 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-01-15 13:25:07.205  INFO 7180 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.41]
2021-01-15 13:25:07.298  INFO 7180 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-01-15 13:25:07.298  INFO 7180 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 918 ms
2021-01-15 13:25:07.487  INFO 7180 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-01-15 13:25:07.676  WARN 7180 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is org.springframework.boot.web.server.PortInUseException: Port 8006 is already in use
2021-01-15 13:25:07.677  INFO 7180 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
2021-01-15 13:25:07.683  INFO 7180 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2021-01-15 13:25:07.700  INFO 7180 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-01-15 13:25:07.714 ERROR 7180 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

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

Description:

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

Action:

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

但我在应用程序属性中更改了 server.port。有用。但是我再次尝试 r运行 我遇到了上述错误。当我一直运行的时候我应该想在application.properties中更改服务器端口。有解决办法吗?

用于您的 tomcat 8006 的端口已被使用。 您需要终止进程并重新运行您的项目

在您的 cmd 上使用它来获取进程的 PID 号:

netstat -ano | findstr :8006

然后使用此命令终止此进程:

taskkill /PID <PID> /F