Java中出现java.lang.IllegalStateException异常错误的解决
Ned_mahone 人气:0java.lang.IllegalStateException异常错误的解决
今天运行项目时出现的这个问题
有错误提示可以看出,大概意思是这个项目已经停止,不能重新加载。也就是说只需重新部署基本就可以啦
网上有人说可以将项目从tomcat中先移除再部署上去,实在不行就把myeclipse中所有项目都清空一下,再从新部署上去,嘿嘿嘿
总之,可以确定这个问题不是代码造成的问题,应该是部署出了问题,将整个项目中心部署一下。tomcat重新启动一下。
java.lang.IllegalStateException: 启动子级时出错
1、情况一:@WebServlet 的配置问题
1.1、错误警告查看
你可以页面搜索一些关键字,看下有没有相同的异常提示/警告
18-Jan-2022 08:57:20.774 严重 [RMI TCP Connection(5)-127.0.0.1] org.apache.tomcat.util.modeler.BaseModelMBean.invoke 调用方法[manageApp]时发生异常
java.lang.IllegalStateException: 启动子级时出错
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:729)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:698)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:747)
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1822)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:293)
at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:809)
at java.management/com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:428)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:376)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:293)
at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:809)
at java.management/com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at java.management/com.sun.jmx.remote.security.MBeanServerAccessController.invoke(MBeanServerAccessController.java:468)
at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1466)
at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1307)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1406)
at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:827)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.apache.catalina.LifecycleException: 无法启动组件[StandardEngine[Catalina].StandardHost[localhost].StandardContext[/my]]
at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)
... 42 more
Caused by: java.lang.IllegalArgumentException: servlet映射中的<url pattern>[mytest1]无效
at org.apache.catalina.core.StandardContext.addServletMappingDecoded(StandardContext.java:3261)
at org.apache.catalina.Context.addServletMappingDecoded(Context.java:905)
at org.apache.catalina.startup.ContextConfig.configureContext(ContextConfig.java:1562)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1329)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:986)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:303)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5068)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
... 43 more
18-Jan-2022 08:57:20.778 严重 [RMI TCP Connection(5)-127.0.0.1] org.apache.tomcat.util.modeler.BaseModelMBean.invoke 调用方法[createStandardContext]时发生异常
javax.management.RuntimeOperationsException: 调用方法[manageApp]时发生异常
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:303)
at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:809)
at java.management/com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:428)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:376)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:293)
at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:809)
at java.management/com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at java.management/com.sun.jmx.remote.security.MBeanServerAccessController.invoke(MBeanServerAccessController.java:468)
at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1466)
at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1307)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1406)
at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:827)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalStateException: 启动子级时出错
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:729)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:698)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:747)
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1822)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:293)
... 34 more
Caused by: org.apache.catalina.LifecycleException: 无法启动组件[StandardEngine[Catalina].StandardHost[localhost].StandardContext[/my]]
at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)
... 42 more
Caused by: java.lang.IllegalArgumentException: servlet映射中的<url pattern>[mytest1]无效
at org.apache.catalina.core.StandardContext.addServletMappingDecoded(StandardContext.java:3261)
at org.apache.catalina.Context.addServletMappingDecoded(Context.java:905)
at org.apache.catalina.startup.ContextConfig.configureContext(ContextConfig.java:1562)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1329)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:986)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:303)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5068)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
... 43 more
[2022-01-18 08:57:20,800] 工件 untitled1:war exploded: 部署工件时出错。请参阅服务器日志了解详细信息。
18-Jan-2022 08:57:30.198 信息 [Catalina-utility-1] org.apache.catalina.startup.HostConfig.deployDirectory 把web 应用程序部署到目录 [D:\softwore\Tomcat\apache-tomcat-10.1.0-M8\webapps\manager]
18-Jan-2022 08:57:30.614 警告 [Catalina-utility-1] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom 使用[SHA1PRNG]创建会话ID生成的SecureRandom实例花费了[310]毫秒。
18-Jan-2022 08:57:30.650 信息 [Catalina-utility-1] org.apache.catalina.startup.HostConfig.deployDirectory Web应用程序目录[D:\softwore\Tomcat\apache-tomcat-10.1.0-M8\webapps\manager]的部署已在[453]毫秒内完成
1.2、详解
前提:
- 这一天我在测试刚学的东西,昨天服务器运行正常,今天刚刚写点测试就报错
- 因为不知道是不是昨天试图让别人访问我的服务器,修改了servlet.xml(**我用的是Tomcat**)
- 所以我第一时间去看了对应文档
行动:
- servlet.xml 发现无误,所以只能查看错误警告:从上到下粗略查看
- 发现关键字**<url pattern>[mytest1]**无效,应该是映射出现了问题
- (前面有提示服务器正常启动,但后面部署工程出现错误)
原因:
- 写映射的时候遗漏了 “ **/** ” ,如图:
- 有绿色波浪线,但是没有飘红,而且也只是提示拼写错误,更换一个字符串而已,所以我没有多想
更改前:
更改后:仍然提示:
2、情况二:XML映射问题
- 异常情况和情况一相同,只是地点换了,错误相同,不过多赘述
- 在写XML映射标签的时候,也是漏了 ” / “
- hello -> /hello
正确形式:
<servlet-mapping> <servlet-name>Mymap</servlet-name> <url-pattern>/hello</url-pattern> </servlet-mapping>
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。
加载全部内容