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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/mvchttp://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/beanshttps://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd">學習自:
https://my.oschina.net/ouyangtaohong/blog/810037
這里面的約束加著springMVC的版本,我試過不可以,所以將版本號去掉也成功了。
總結:
就像大佬說的,在spring啟動的時候,會從spring配置文件中配置的xsd地址下載信息,如果你沒有配置版本信息,則會從你的本地加載。如果寫了和你引入的spring版本信息相同的版本,則也會從本地加載,如果不和你引入的匹配,則從外網下載。
這是約束寫的不對導致的啟動緩慢問題,當然也可能是其他原因,這只是我的一種情況。
如有錯誤請指出謝謝!
總結
以上是生活随笔為你收集整理的spring项目启动慢问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 怎么样优化可以避免百度的冰桶算法?
- 下一篇: 冰桶算法是什么