竹杖芒鞋轻胜马,谁怕?一蓑烟雨任平生(=・ω・=)|

IIIID

园龄:4年5个月粉丝:3关注:23

日常问题-使用maven jetty插件启动慢的一些解决方法

背景

开发工具-idea

使用maven的jetty插件启动web(spring)项目时,可能会遇到项目启动很慢,甚至可能直接timeout或者报一些其他错误。我们可以根据错误来优化maven中jetty的启动速度。

常见错误一

当遇到类似如下错误:

java.lang.ArrayIndexOutOfBoundsException: 51889

或者:

java.lang.Exception: Timeout scanning annotations

解决办法

在web.xml中的web-app标签设置属性metadata-complete=”true”

<web-app 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_3_0.xsd"
     version="3.0" metadata-complete="true">

 

产生原因

官方原因解释如下:

One important thing to be aware of is that the 2.5 Servlet Specification has introduced a new attribute into the 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来检查的。

常见错误二

出现如下提示信息:

[INFO] No Transaction manager found - if your webapp requires one, please configure one.

解决办法

首先修改pom.xml中jetty插件的配置:

复制代码
<plugins>
    <plugin>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>9.3.0.M1</version>
        <configuration>
            <httpConnector>
                <port>8888</port>
            </httpConnector>
            <!-- 本地装载contextXml,来解决未配置事务或数据库造成启动时等待时间过长 -->
            <contextXml>src/main/resources/jetty-deploy.xml</contextXml>
        </configuration>
    </plugin>
</plugins>
复制代码

 

关键是新增了contextXml项的配置,jetty-deploy.xml具体内容如下:

复制代码
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<!-- =============================================================== -->
<!-- Add a ContextProvider to the deployment manager                 -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- This scans the webapps directory for war files and directories  -->
<!-- to deploy.                                                      -->
<!-- This configuration must be used with jetty-deploy.xml, which    -->
<!-- creates the deployment manager instance                         -->
<!-- =============================================================== -->
<Configure id="Server" class="org.eclipse.jetty.webapp.WebAppContext">
    <Call name="setAttribute">
        <Arg>org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern</Arg>
        <Arg>.*/mwa-web-.*\.jar$</Arg>
        <!--<Arg>.*/.*jsp-api-[^/]\.jar$|./.*jsp-[^/]\.jar$|./.*taglibs[^/]*\.jar$</Arg>-->
    </Call>
</Configure>
复制代码

 

产生原因

项目中未配置事务或数据库造成启动时等待时间过长。

 

 

 

参考:关于使用maven jetty插件启动慢的解决方法 | Zacard's Notes

本文作者:IIIID

本文链接:https://www.cnblogs.com/Oxyy/p/14949074.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   IIIID  阅读(864)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
· Manus的开源复刻OpenManus初探
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起