尝试运行基于Maven的简单springboot项目时出现错误

时间:2019-12-26 23:11:29

标签: spring-boot tomcat

我试图在端口8082上运行springboot项目。但是它一次又一次失败。请给我一个可行的解决方案。 完整的堆栈跟踪:

.   ____          _            __ _ _

/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \

( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \

\\/  ___)| |_)| | | | | || (_| |  ) ) ) )

  '  |____| .__|_| |_|_| |_\__, | / / / /

=========|_|==============|___/=/_/_/_/

:: Spring Boot ::        (v2.2.2.RELEASE)



2019-12-26 18:02:23.947  INFO 3680 --- [  restartedMain] c.i.s.w.s.SpringBootFirstWebApplication  : Starting SpringBootFirstWebApplication on DESKTOP-BK9RRM4 with PID 3680 (C:\Users\zunayeed\springboot-workspace01\spring-boot-first-web-application\spring-boot-first-web-application\target\classes started by zunayeed in C:\Users\zunayeed\springboot-workspace01\spring-boot-first-web-application\spring-boot-first-web-application)

2019-12-26 18:02:23.953  INFO 3680 --- [  restartedMain] c.i.s.w.s.SpringBootFirstWebApplication  : No active profile set, falling back to default profiles: default

2019-12-26 18:02:24.294  INFO 3680 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable

2019-12-26 18:02:24.295  INFO 3680 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'

2019-12-26 18:02:29.465  INFO 3680 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8082 (http)

2019-12-26 18:02:29.514  INFO 3680 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]

2019-12-26 18:02:29.515  INFO 3680 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.29]

2019-12-26 18:02:29.926  INFO 3680 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext

2019-12-26 18:02:29.927 DEBUG 3680 --- [  restartedMain] o.s.web.context.ContextLoader            : Published root WebApplicationContext as ServletContext attribute with name [org.springframework.web.context.WebApplicationContext.ROOT]

2019-12-26 18:02:29.927  INFO 3680 --- [  restartedMain] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 5628 ms

2019-12-26 18:02:30.726  INFO 3680 --- [  restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'

2019-12-26 18:02:30.744 DEBUG 3680 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : ControllerAdvice beans: 0 @ModelAttribute, 0 @InitBinder, 1 RequestBodyAdvice, 1 ResponseBodyAdvice

2019-12-26 18:02:31.039 DEBUG 3680 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : 2 mappings in 'requestMappingHandlerMapping'

2019-12-26 18:02:31.130 DEBUG 3680 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Patterns [/webjars/**, /**] in 'resourceHandlerMapping'

2019-12-26 18:02:31.165 DEBUG 3680 --- [  restartedMain] .m.m.a.ExceptionHandlerExceptionResolver : ControllerAdvice beans: 0 @ExceptionHandler, 1 ResponseBodyAdvice

2019-12-26 18:02:31.345  WARN 3680 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : Unable to start LiveReload server

2019-12-26 18:02:31.811  INFO 3680 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]

2019-12-26 18:02:31.830  INFO 3680 --- [  restartedMain] ConditionEvaluationReportLoggingListener :



Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

2019-12-26 18:02:31.832 ERROR 3680 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   :



***************************

APPLICATION FAILED TO START

***************************



Description:



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



Action:


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



2019-12-26 18:02:31.837  INFO 3680 --- [  restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'

2 个答案:

答案 0 :(得分:0)

说明

  

Web服务器无法启动。端口8082已被使用。

操作

  

识别并停止正在侦听端口8082的进程,或者将该应用程序配置为侦听另一个端口。

可能的原因

  • 您已经在运行应用程序
  • 或者另一个应用程序正在同一端口上运行

解决方案

  • 配置应用程序以侦听另一个端口(例如:8081)

    如果您使用的是applcation.properties

    server.port=8081
    

    如果您使用的是application.yml

    server:
       port: 8081
    
  • 识别并停止正在监听端口(8082)的进程

    并重新启动您的应用程序

答案 1 :(得分:0)

如果您使用的是cmd或git bash,请使用以下命令:

netstat -ano

或更进一步的细粒度查询:

nestat -ano | grep {port addr}  

(注意:grep仅适用于linux或gitbash,对于cmd使用findstr

标识当前正在运行的所有PID,这些PID使用您要在应用程序中使用的特定端口地址。如果PID不相关,则可以使用命令kill -9 {pid}终止PID。之后,您可以在同一端口启动应用程序。

另一种简便的方法是使用其他任何应用程序都未使用的另一个端口地址。只需在server.port=8086中设置属性application.properties,或在启动应用程序时将其作为参数传递。