Jetty在Spring工程中启动报错

在使用Jetty运行Spring工程时遇到启动问题,通过在web.xml文件的web-app标签中添加metadata-complete="true"属性可以解决。此设置有助于正确解析应用的元数据,避免启动报错。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

启动时报错信息如下:

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.youkuaiyun.com/eclipser1987/article/details/6385424


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值