0

我正在尝试使用 JSF、JPA、Spring 构建一个项目,但我无法成功。我使用 JBoss 作为我的服务器。它显示没有错误,但显示 404 错误。有趣的是,当我使用 Tomcat 时,控制台是清晰的,但是在加载页面上它显示,

解析 /index.xhtml 时出错:不支持设置属性http://xml.org/sax/properties/lexical-handler

这是完整的堆栈跟踪

javax.faces.view.facelets.FaceletException: Error Parsing /index.xhtml: not supported setting property http://xml.org/sax/properties/lexical-handler
    at com.sun.faces.facelets.compiler.SAXCompiler.doCompile(SAXCompiler.java:425)
    at com.sun.faces.facelets.compiler.SAXCompiler.doMetadataCompile(SAXCompiler.java:408)
    at com.sun.faces.facelets.compiler.Compiler.metadataCompile(Compiler.java:130)
    at com.sun.faces.facelets.impl.DefaultFaceletFactory.createMetadataFacelet(DefaultFaceletFactory.java:327)
    at com.sun.faces.facelets.impl.DefaultFaceletFactory.access$200(DefaultFaceletFactory.java:93)
    at com.sun.faces.facelets.impl.DefaultFaceletFactory$2.newInstance(DefaultFaceletFactory.java:166)
    at com.sun.faces.facelets.impl.DefaultFaceletFactory$2.newInstance(DefaultFaceletFactory.java:164)
    at com.sun.faces.facelets.impl.DefaultFaceletCache$2.newInstance(DefaultFaceletCache.java:94)
    at com.sun.faces.facelets.impl.DefaultFaceletCache$2.newInstance(DefaultFaceletCache.java:89)
    at com.sun.faces.util.ExpiringConcurrentCache$1.call(ExpiringConcurrentCache.java:99)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at com.sun.faces.util.ExpiringConcurrentCache.get(ExpiringConcurrentCache.java:114)
    at com.sun.faces.facelets.impl.DefaultFaceletCache.getViewMetadataFacelet(DefaultFaceletCache.java:143)
    at com.sun.faces.facelets.impl.DefaultFaceletCache.getViewMetadataFacelet(DefaultFaceletCache.java:62)
    at com.sun.faces.facelets.impl.DefaultFaceletFactory.getMetadataFacelet(DefaultFaceletFactory.java:260)
    at com.sun.faces.facelets.impl.DefaultFaceletFactory.getMetadataFacelet(DefaultFaceletFactory.java:209)
    at com.sun.faces.application.view.ViewMetadataImpl.createMetadataView(ViewMetadataImpl.java:114)
    at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:233)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Unknown Source)  

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

  <display-name>Jsf_Spring_Jpa</display-name>

     <!-- Welcome Page -->
   <welcome-file-list>
     <welcome-file>index.xhtml</welcome-file>
   </welcome-file-list>

    <!-- JSF Servlet is defined to container -->
   <servlet>
     <servlet-name>Faces Servlet</servlet-name>
     <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
     <load-on-startup>1</load-on-startup>
   </servlet>

   <!-- Mapping with servlet and url for the http requests. -->

  <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.faces</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>

   <!-- Spring Context Configuration' s Path definition -->
   <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value> /WEB-INF/applicationContext.xml</param-value>
   </context-param>

   <context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
  </context-param>

   <!-- Project Stage Level -->
   <context-param>
     <param-name>javax.faces.PROJECT_STAGE</param-name>
     <param-value>Development</param-value>
   </context-param>

   <!-- The Bootstrap listener to start up and shut down Spring's root WebApplicationContext. It is registered to Servlet Container -->
   <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
   </listener>

   <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
   </listener>

    <listener>
         <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
    </listener>
</web-app>  

这是如何引起的,我该如何解决?

4

2 回答 2

4

此错误来自pull-parser它的可选依赖项dom4j。您可能无意中在您的类路径上获得了 pull-parser,即使它对于 dom4j 是可选的。尝试显式排除它并改用 JDK 的内置解析器(例如com.sun.org.apache.xerces.internal.parsers.SAXParser),它应该在默认情况下执行此操作。

这个问题已有 6 年历史,因此以下问题不可能是问题,但是:在我的 Gradle 项目中,从 Gradle 5.4 升级到 Gradle 6.5 突然导致pull-parser由于依赖于类路径,dom4j尽管如上所述,依赖于dom4jonpull-parser是可选的,以前没有发生。我已将此报告给 Gradle 项目:https ://github.com/gradle/gradle/issues/13656 。

于 2020-07-01T20:38:43.460 回答
2

我通过添加以下依赖项(在 Gradle 语法中)摆脱了错误:

implementation 'pull-parser:pull-parser:2.1.10'
于 2020-12-17T16:13:48.310 回答