1. 程式人生 > >Jetty在Spring工程中啟動報錯

Jetty在Spring工程中啟動報錯

啟動時報錯資訊如下:
java.lang.ArrayIndexOutOfBoundsException: 48188
	at org.objectweb.asm.ClassReader.readClass(Unknown Source)
	at org.objectweb.asm.ClassReader.accept(Unknown Source)
	at org.objectweb.asm.ClassReader.accept(Unknown Source)
	at org.eclipse.jetty.annotations.AnnotationParser.scanClass(AnnotationParser.java:646)
	at org.eclipse.jetty.annotations.AnnotationParser$2.processEntry(AnnotationParser.java:618)
	at org.eclipse.jetty.webapp.JarScanner.matched(JarScanner.java:155)
	at org.eclipse.jetty.util.PatternMatcher.matchPatterns(PatternMatcher.java:82)
	at org.eclipse.jetty.util.PatternMatcher.match(PatternMatcher.java:64)
	at org.eclipse.jetty.webapp.JarScanner.scan(JarScanner.java:78)
	at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:630)
	at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:639)
	at org.eclipse.jetty.annotations.AnnotationConfiguration.parseWebInfLib(AnnotationConfiguration.java:282)
	at org.eclipse.jetty.annotations.AnnotationConfiguration.configure(AnnotationConfiguration.java:92)
	at org.eclipse.jetty.webapp.WebAppContext.configure(WebAppContext.java:427)
	at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1207)
	at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:610)
	at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:453)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
	at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:89)
	at org.eclipse.jetty.server.Server.doStart(Server.java:262)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
	at runjettyrun.Bootstrap.main(Bootstrap.java:80)

解決方法為:在web.xml中 web-app標籤設定屬性metadata-complete="true"

如下:

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	metadata-complete="true">

官方原因解釋如下:

One important thing to be aware of is that the 2.5 Servlet Specification has introduced a new attribute into the <web-app> element, the metadata-complete attribute. If true, then the web container will NOT search the webapp for source code annotations, and your web.xml file must contain all resources required. If false or not specified, then jetty is required to examine all servlets, filters and listeners in the webapp for annotations. Therefore, you can save startup time by using this attribute correctly - if you don't want to use annotations then ensure you mark metadata-complete="true", otherwise you will pay the penalty of the code examination.
就是說如果不設定metadata-complete="true",那麼jetty會檢查程式中所有的annotations,程式中spring和其他的annotations不需要jetty來檢查

參考文章:http://blog.csdn.net/eclipser1987/article/details/6385424