FacesServlet无法在Web片段中工作

Moh*_*ami 2 myfaces jsf-2 facesservlet web-fragment

我有两个Web应用程序(web-module1.war和web-module2.war),我想使用Web片段(web-core.jar)进行常见的servlet声明,如FacesServlet.

当我在web.xml中声明FacesServlet没问题,但是当我将此声明移动到web-fragment.xml时,我收到此错误:

java.lang.IllegalStateException: No Factories configured for this Application. 
This happens if the faces-initialization does not work at all - make sure that you properly include all configuration settings necessary for a basic faces application and that all the necessary libs are included. Also check the logging output of your web application and your container for any exceptions!
If you did that and find nothing, the mistake might be due to the fact that you use some special web-containers which do not support registering context-listeners via TLD files and a context listener is not setup in your web.xml.
A typical config looks like this;
<listener>
  <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
Run Code Online (Sandbox Code Playgroud)

我没有其他servlet /过滤器声明的这个问题!

web-fragment.xml位于web-core.jar的META-INF文件夹以及faces-config.xml中.

web-core.jar被声明为maven依赖项(我可以在WEB-INF/lib中找到它).

这是web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" metadata-complete="false"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
        http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

    <absolute-ordering>
        <name>core_web_fragment</name>
    </absolute-ordering>

</web-app>
Run Code Online (Sandbox Code Playgroud)

和web-fragment.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-fragment metadata-complete="true" version="3.0"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd">

    <name>core_web_fragment</name>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-*.xml</param-value>
    </context-param>
    <!-- /Spring Config -->
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
        <param-value>true</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>inscription.xhtml</welcome-file>
    </welcome-file-list>
</web-fragment>
Run Code Online (Sandbox Code Playgroud)

我正在使用Tomcat7

red*_* la 5

如果您正在使用Apache Myfaces JSF实现,这是一个已知的错误

所以你应该改变它(例如使用MOJARRA)