日常问题-使用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>
产生原因
项目中未配置事务或数据库造成启动时等待时间过长。
本文作者:IIIID
本文链接:https://www.cnblogs.com/Oxyy/p/14949074.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core内存结构体系(Windows环境)底层原理浅谈
· C# 深度学习:对抗生成网络(GAN)训练头像生成模型
· .NET 适配 HarmonyOS 进展
· .NET 进程 stackoverflow异常后,还可以接收 TCP 连接请求吗?
· SQL Server统计信息更新会被阻塞或引起会话阻塞吗?
· 本地部署 DeepSeek:小白也能轻松搞定!
· 传国玉玺易主,ai.com竟然跳转到国产AI
· 自己如何在本地电脑从零搭建DeepSeek!手把手教学,快来看看! (建议收藏)
· 我们是如何解决abp身上的几个痛点
· 如何基于DeepSeek开展AI项目