tomcat啟動錯誤整理(三)
阿新 • • 發佈:2019-01-04
1.Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/websocket]]錯誤
Connected to server [2018-07-25 05:28:47,397] Artifact websocket:war exploded: Artifact is being deployed, please wait... 七月 25, 2018 5:28:47 下午 org.apache.catalina.loader.WebappClassLoader validateJarFile 資訊: validateJarFile(C:\git-learn\websocket\target\websocket\WEB-INF\lib\javaee-api-7.0.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class # 未載入javaee-api-7.0.jar 七月 25, 2018 5:28:47 下午 org.apache.catalina.loader.WebappClassLoader validateJarFile 資訊: validateJarFile(C:\git-learn\websocket\target\websocket\WEB-INF\lib\javax.servlet-api-3.1.0.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class # 未載入javax.servlet-api-3.1.0.jar 七月 25, 2018 5:28:49 下午 org.apache.catalina.core.ContainerBase addChildInternal 嚴重: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/websocket]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632) at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1740) 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.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:618) at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:565) 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.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468) at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76) at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309) at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401) at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829) 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 sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:324) at sun.rmi.transport.Transport$1.run(Transport.java:200) at sun.rmi.transport.Transport$1.run(Transport.java:197) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:196) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.IllegalArgumentException: The segment [userCode={userCode}] is not valid in the provided path [/webs/userCode={userCode}] at org.apache.tomcat.websocket.server.UriTemplate.<init>(UriTemplate.java:90) at org.apache.tomcat.websocket.server.WsServerContainer.addEndpoint(WsServerContainer.java:185) at org.apache.tomcat.websocket.server.WsServerContainer.addEndpoint(WsServerContainer.java:272) at org.apache.tomcat.websocket.server.WsSci.onStartup(WsSci.java:143) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5456) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 42 more
解決:
step1:所屬pom.xml檔案中新增provide,解決未載入兩個jar包的問題
<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> # 新增 </dependency> <dependency> <!-- 支援websocket --> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>7.0</version> <scope>provided</scope> # 新增 </dependency>
step2:去除錯誤程式碼
@ServerEndpoint(value = "/wbs/{userCode}") //@ServerEndpoint(value = "/webs?userCode={userCode}&userName={userName}"),這行錯誤程式碼導致 public class WebsocketUnit { // vars private Session session;// 封裝了websocket會話 private String userCode;// 訪問使用者 // websocket請求確立後,會執行onopen註解的function @OnOpen public void onOpen(Session session, @PathParam("userCode") String userCode) { // 連線確定,初始化session和userCode this.session = session; this.userCode = userCode; System.out.println("訪問使用者userCode=" + userCode); System.out.println(session.getRequestParameterMap()); } }