jetty測試時,報異常 以下:java
java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0( Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.eclipse.jetty.webapp.IterativeDescriptorProcessor.visit(IterativeDescriptorProcessor.java:83) at org.eclipse.jetty.webapp.IterativeDescriptorProcessor.process(IterativeDescriptorProcessor.java:70) at org.eclipse.jetty.webapp.MetaData.resolve(MetaData.java:402 ) at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1339) at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:772) at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:263) at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:517 ) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132) at org.eclipse.jetty.server.Server.start( Server.java:405) at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:106) at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61) at org.eclipse.jetty.server.Server.doStart(Server.java:372 ) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at soc.main.SocMain.main( SocMain.java:41) Caused by: java.lang.NoSuchFieldError: MAX_INACTIVE_MINUTES at org.eclipse.jetty.webapp.StandardDescriptorProcessor.visitSessionConfig(StandardDescriptorProcessor.java:653) ... 19 more
即StandardDescriptorProcessor類裏沒有MAX_INACTIVE_MINITES這一屬性。這一屬性引用的是jetty-server包下的AbstractSessionManager類裏的該屬性。也就是說所依賴的jetty-server包下沒有該屬性。另外,web
NoSuchFieldError及NoSuchMethodError多半是jar包的版本不對,因而查看 了下jetty相關jar包,以下:app
<dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-webapp</artifactId> <version>9.3.8.v20160314</version> </dependency> …………………… <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-servlet</artifactId> <version>9.3.7.v20160115</version> </dependency>
可看出jetty-webapp和jetty-servlet是不一樣版本。而個人依賴裏並無jetty-server包,那麼確定是至少其中一個包依賴了jetty-server包。查看下便知jetty-webapp依賴了jetty-servlet,而jetty-servlet依賴了jetty-security,而jetty-security又依賴了jetty-server包,而jetty-server 9.3.7版本的AbstractSessionManager裏沒有MAX_INACTIVE_MINITES屬性,因此jetty-webapp 9.3.8版本下的StandardDescriptorProcessor類引用該屬性就會報這個異常。因此,只需將jetty-servlet的版本改爲9.3.8或者jetty-webapp版本改成9.3.7,即讓再者版本一致。修改後的以下:eclipse
<dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-webapp</artifactId> <version>9.3.8.v20160314</version> </dependency> …………………… <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-servlet</artifactId> <version>9.3.8.v20160314</version> </dependency>