Tomcat 7.0.12 報錯 org.apache.catalina.deploy.WebXml addFilter

今天工作的時候從SVN新下載了一個項目,用的Tomcat 7.0.52 啓動的,雖然項目能啓動,但是有些頁面報錯:

java.io.FileNotFoundException: Could not resolve XML resource 
[null] with public ID [***] and base URI [null] to a known, local entity.

是因爲 自從7.0.52版本後出於安全考慮將 xmlBlockExternal=”true”
官方解釋:

As per discussion with Tomcat developers, xmlBlockExternal=”true” 
attribute of Tomcat’s Context (context.xml) was set true by default 
starting from 7.0.52. With xmlBlockExternal=”false” generated/djn-
settings.conf can be included` ontext  xmlBlockExternal="false">

可以將 Tomcat conf目錄下的context.xml的 contex 節點上加上一個屬性
xmlBlockExternal=”false”


然後我下載了一個低版本的 Tomcat 7.0.12 ,運行後又出現下面的錯誤,我將主要的信息截了出來:

2017-4-28 10:32:25 org.apache.tomcat.util.digester.Digester endElement
嚴重: End event threw exception
java.lang.NoSuchMethodException: org.apache.catalina.deploy.WebXml addFilter
    at org.apache.tomcat.util.IntrospectionUtils.callMethod1(IntrospectionUtils.java:802)
    at org.apache.tomcat.util.digester.SetNextRule.end(SetNextRule.java:201)
    at org.apache.tomcat.util.digester.Digester.endElement(Digester.java:1057)
    at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
.....
2017-4-28 10:32:25 org.apache.catalina.startup.ContextConfig parseWebXml
嚴重: Parse error in application web.xml file at jndi:/localhost/B-SDM/WEB-INF/web.xml
java.lang.NoSuchMethodException: org.apache.catalina.deploy.WebXml addFilter
    at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.java:2687)
    at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.java:2713)
    at org.apache.tomcat.util.digester.Digester.endElement(Digester.java:1060)
    at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
......
2017-4-28 10:32:25 org.apache.catalina.startup.ContextConfig parseWebXml
嚴重: Occurred at line 21 column 11
2017-4-28 10:32:25 org.apache.catalina.startup.ContextConfig configureStart
嚴重: Marking this application unavailable due to previous error(s)

這個錯的解決方法是在Tomcat的 conf目錄下的context.xml配置文件中的 Context 節點上加入 配置.

<Loader delegate="true" /> 

關於< Loader delegate=”true” /> 節點:

設置爲 true,表示tomcat將遵循JVM的delegate機制,即一個WebAppClassLoader在加載類文件時,會先遞交給SharedClassLoader加載,SharedClassLoader無法加載成功,會繼續向自己的父類委託,一直到BootstarpClassLoader,如果都沒有加載成功,則最後由WebAppClassLoader自己進行加載。
設置成 false,表示將不遵循這個delegate機制,即WebAppClassLoader在加載類文件時,會優先自己嘗試加載,如果加載失敗,纔會沿着繼承鏈,依次委託父類加載。
關於類加載的機制,將在稍後的博客中總結.

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