spring项目启动慢问题

问题:

这个问题在我学spring框架的时候就出现过,当时启动缓慢一直卡在控制台项目。但是耐心等是可以出来的。当我学到springMVC的时候又是这样,而且tomcat启动打印日志又卡住了如下图
在这里插入图片描述
忍无可忍我上网搜了好多但是都问题不匹配。我下面又自己尝试是卡在那个环节了。
因为我学spring的时候就遇到过,所以下意识认为是spring框架配置文件的问题,于是在这个springMVC的入门程序中我将servlet扫描springMVC配置文件的部分注释掉试着再次启动,果不其然速度刷刷的启动了。
在这里插入图片描述
所以问题出现在spring配置文件。

解决:

我们将springmvc配置文件中的约束换成下面这个即可:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context.xsd
                        http://www.springframework.org/schema/mvc
                        http://www.springframework.org/schema/mvc/spring-mvc.xsd">

我以前的是这样的,区别其实就是引入spring-context和spring-mvc的顺序不一样,可能这会导致寻找不到对应的xsd所以导致项目卡住:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        https://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">

学习自:
https://my.oschina.net/ouyangtaohong/blog/810037

这里面的约束加着springMVC的版本,我试过不可以,所以将版本号去掉也成功了。

总结:

就像大佬说的,在spring启动的时候,会从spring配置文件中配置的xsd地址下载信息,如果你没有配置版本信息,则会从你的本地加载。如果写了和你引入的spring版本信息相同的版本,则也会从本地加载,如果不和你引入的匹配,则从外网下载。

这是约束写的不对导致的启动缓慢问题,当然也可能是其他原因,这只是我的一种情况。

如有错误请指出谢谢!

发布了57 篇原创文章 · 获赞 11 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_42419462/article/details/104180710
今日推荐