bug筆記 - Spring --- Tomcat 報錯: SEVERE: One or more listeners failed to start.

emmm, 最近把Spring框架也學的差不多了, 因爲最近要開始迭代小組圖書管理系統2.0, 不太有時間再總結Spring In Action的學習筆記了, 所以把Spring學習筆記先放一段時間啦~


1. bug描述: 在寫Spring代碼的時候, 啓動Tomcat時報錯.

2. bug信息:

Connected to server
[2017-11-16 09:28:36,551] Artifact Spring_10:war exploded: Artifact is being deployed, please wait...
Nov 16, 2017 9:28:37 PM org.apache.catalina.loader.WebappClassLoaderBase validateJarFile
INFO: validateJarFile(/home/dela/IdeaProjects/Spring/Spring_10/out/artifacts/Spring_10_war_exploded/WEB-INF/lib/javax.servlet-api-3.1.0.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
Nov 16, 2017 9:28:38 PM org.apache.catalina.deploy.WebXml setVersion
WARNING: Unknown version string [3.1]. Default version will be used.
Nov 16, 2017 9:28:42 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://www.springframework.org/tags is already defined
Nov 16, 2017 9:28:42 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://www.springframework.org/tags/form is already defined
Nov 16, 2017 9:28:42 PM org.apache.catalina.startup.TldConfig execute
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Nov 16, 2017 9:28:43 PM org.apache.catalina.core.StandardContext startInternal
**SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file**
Nov 16, 2017 9:28:43 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [] startup failed due to previous errors
[2017-11-16 09:28:43,528] Artifact Spring_10:war exploded: Error during artifact deployment. See server log for details.

3. bug解決:

這個bug相當詭異啊, 它詭異在IDEA的報錯信息只有一句話: SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file, 信息裏面提示去查看錯誤日誌, 但是IDEA下面的錯誤日誌是空! 這就很尷尬, 因爲僅憑這一句話, 沒辦法定位錯誤出在哪裏.

(1) 找到錯誤日誌

之前問過恆毅, 他說如果IDEA下面沒有錯誤日誌, 就去tomcat安裝包下面的logs目錄裏面找, 但是然而並沒有找到, 只有一些很久之前的錯誤日誌.

後來才知道, 錯誤日誌在/home/dela/.IntelliJIdea2017.1/system/tomcat/Unnamed_Spring_10(當前Project的名字)下, 也就是家目錄下的.IntelliJIdea2017.1/system/tomcat, 然後找到本工程的tomcat名字, 進入logs目錄就能看到當天的錯誤日誌了.

我是在localhost.2017-11-16.log 中找到問題的原因的, 錯誤信息如下:

Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/classpath*:db-config.properties]
    at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:141)
    at org.springframework.core.io.support.EncodedResource.getInputStream(EncodedResource.java:153)
    at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:98)
    at org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(PropertiesLoaderSupport.java:175)
    at org.springframework.core.io.support.PropertiesLoaderSupport.mergeProperties(PropertiesLoaderSupport.java:156)
    at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:80)
    ... 52 more

(2) 解決問題

原因是我的一個XML文件在載入properties配置文件時路徑不對, 我把它放在了resources目錄下(但是爲什麼放在resources目錄下它會找不到現在還不清楚), 導致文件無法被加載, 將這個文件放入WEB-INF下, 通過/WEB-INF/db-config.properties就能訪問加載到了!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章