解决tomcat启动报错:一个或多个listeners启动失败问题

本站所有内容来自互联网收集,仅供学习和交流,请勿用于商业用途。如有侵权、不妥之处,请第一时间联系我们删除!Q群:迪思分享

免费资源网 – https://freexyz.cn/

tomcat启动报错:一个或多个listeners启动失败

这种错误一般是在javaweb项目中使用监听器时出现的。

造成的原因时

没有在web.xml文件中配置全局参数。

如图:

解决tomcat启动报错:一个或多个listeners启动失败问题插图

具体原理

当我们使用spring自带的工具类WebApplicationContextUtils时,在它的方法ContextLoaderListener方法中,会在web应用启动时就加载配置文件(为了防止每次执行业务都加载一次配置文件和spring容器,节约内存),所以把每次要加载的配置文件抽取出来,做成一个全局参数,得到后,继而创建上下文对象Application,并将其存储到最大的域ServletContext中,从而可以在任何地方获得并使用Application对象。

**注:**如果是自己写的监听器,上图中不需要写classpath:

启动tomcat服务器时出现错误

启动Tomcat服务器时出现如下错误:

解决方式

是因为Tomcat服务器启动多次,导致服务器的端口被占用,关闭服务器,然后重新启动就可以了。

六月 23, 2023 7:01:29 上午 org.apache.coyote.AbstractProtocol init信息: Initializing ProtocolHandler [“http-bio-80”]六月 23, 2023 7:01:29 上午 org.apache.coyote.AbstractProtocol init严重: Failed to initialize end point associated with ProtocolHandler [“http-bio-80”]java.net.BindException: Address already in use: JVM_Bind <null>:80    at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:406)    at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:610)    at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:429)    at org.apache.coyote.http11.AbstractHttp11JsseProtocol.init(AbstractHttp11JsseProtocol.java:119)    at org.apache.catalina.connector.Connector.initInternal(Connector.java:981)    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)    at org.apache.catalina.core.StandardService.initInternal(StandardService.java:559)    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)    at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:814)    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)    at org.apache.catalina.startup.Tomcat.start(Tomcat.java:335)    at org.apache.tomcat.maven.plugin.tomcat7.run.AbstractRunMojo.startContainer(AbstractRunMojo.java:1091)    at org.apache.tomcat.maven.plugin.tomcat7.run.AbstractRunMojo.execute(AbstractRunMojo.java:512)    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:956)    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)    at org.apache.maven.cli.MavenCli.main(MavenCli.java:192)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)    at java.lang.reflect.Method.invoke(Method.java:498)    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)    at org.codehaus.classworlds.Launcher.main(Launcher.java:47)Caused by: java.net.BindException: Address already in use: JVM_Bind    at java.net.DualStackPlainSocketImpl.bind0(Native Method)    at java.net.DualStackPlainSocketImpl.socketBind(DualStackPlainSocketImpl.java:102)    at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:513)    at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:180)    at java.net.ServerSocket.bind(ServerSocket.java:375)    at java.net.ServerSocket.<init>(ServerSocket.java:237)    at java.net.ServerSocket.<init>(ServerSocket.java:181)    at org.apache.tomcat.util.net.DefaultServerSocketFactory.createSocket(DefaultServerSocketFactory.java:49)    at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:393)    … 36 more

六月 23, 2023 7:01:29 上午 org.apache.catalina.core.StandardService initInternal严重: Failed to initialize connector [Connector[HTTP/1.1-80]]org.apache.catalina.LifecycleException: Failed to initialize component [Connector[HTTP/1.1-80]]    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:106)    at org.apache.catalina.core.StandardService.initInternal(StandardService.java:559)    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)    at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:814)    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)    at org.apache.catalina.startup.Tomcat.start(Tomcat.java:335)    at org.apache.tomcat.maven.plugin.tomcat7.run.AbstractRunMojo.startContainer(AbstractRunMojo.java:1091)    at org.apache.tomcat.maven.plugin.tomcat7.run.AbstractRunMojo.execute(AbstractRunMojo.java:512)    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:956)    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)    at org.apache.maven.cli.MavenCli.main(MavenCli.java:192)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)    at java.lang.reflect.Method.invoke(Method.java:498)    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)    at org.codehaus.classworlds.Launcher.main(Launcher.java:47)Caused by: org.apache.catalina.LifecycleException: Protocol handler initialization failed    at org.apache.catalina.connector.Connector.initInternal(Connector.java:983)    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)    … 31 moreCaused by: java.net.BindException: Address already in use: JVM_Bind <null>:80    at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:406)    at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:610)    at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:429)    at org.apache.coyote.http11.AbstractHttp11JsseProtocol.init(AbstractHttp11JsseProtocol.java:119)    at org.apache.catalina.connector.Connector.initInternal(Connector.java:981)    … 32 moreCaused by: java.net.BindException: Address already in use: JVM_Bind    at java.net.DualStackPlainSocketImpl.bind0(Native Method)    at java.net.DualStackPlainSocketImpl.socketBind(DualStackPlainSocketImpl.java:102)    at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:513)    at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:180)    at java.net.ServerSocket.bind(ServerSocket.java:375)    at java.net.ServerSocket.<init>(ServerSocket.java:237)    at java.net.ServerSocket.<init>(ServerSocket.java:181)    at org.apache.tomcat.util.net.DefaultServerSocketFactory.createSocket(DefaultServerSocketFactory.java:49)    at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:393)    … 36 more

六月 23, 2023 7:01:29 上午 org.apache.catalina.core.StandardService startInternal信息: Starting service Tomcat六月 23, 2023 7:01:29 上午 org.apache.catalina.core.StandardEngine startInternal信息: Starting Servlet Engine: Apache Tomcat/7.0.37

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。


© 版权声明
THE END
★喜欢这篇文章吗?喜欢的话,麻烦动动手指支持一下!★
点赞11 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容