jetty NoSuchFieldError: MAX_INACTIVE_MINUTES

jetty测试时,报异常  如下:

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包下没有该属性。另外,

NoSuchFieldError及NoSuchMethodError多半是jar包的版本不对,于是查看 了下jetty相关jar包,如下:

            <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,即让再者版本一致。修改后的如下:

<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>


你可能感兴趣的:(jetty NoSuchFieldError: MAX_INACTIVE_MINUTES)