Maven - JSF 2.0 does not work on embedded tomcat

I created a Maven web application using JSF 2.2, Primefaces, Tomcat 7 dependencies.

My JSF implementation is Mojarra 2.2.4, I added this dependency to my POM:

    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.2.4</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.2.4</version>
        <scope>compile</scope>
    </dependency>

But unfortunately, I have a problem with tomcat7-maven-pluginand its built-in tomcat. If I use the command tomcat7:run, my webapp starts without problems, but when it tries to load a managed bean, I get this error:

Target unavailability, identifier 'testBean' allowed for null

This is a sign that webapp is using JSF 1.xinstead JSF 2.x. The configurator JSF 1.xdoes not recognize annotations @ManagedBean, which will lead to the fact that they will not be loaded / initialized automatically without the need for faces-config.xml.

tomcat embedded 7.0.50, : http://tomcat.apache.org/maven-plugin-trunk/tomcat7-maven-plugin/adjust-embedded-tomcat-version.html

, , @ManagedBean, managedbean faces-config.xml.

JSF 2.x Tomcat Embedded maven7-tomcat-plugin?

PS: tomcat7:run-war , , , , , xhtml (,) .

+4
1

Mojarra 2.2.4 MyFaces 2.2.0, :

  • Mojarra POM
  • MyFaces POM:

    <dependency>
        <groupId>org.apache.myfaces.core</groupId>
        <artifactId>myfaces-api</artifactId>
        <version>2.2.0</version>
        <scope>compile</scope>
    </dependency>
    
    <dependency>
        <groupId>org.apache.myfaces.core</groupId>
        <artifactId>myfaces-impl</artifactId>
        <version>2.2.0</version>
        <scope>compile</scope>
    </dependency>
    
  • - web.xml

    <listener>
    <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
    

  • web.xml

    <context-param>
         <description>Defines which packages to scan for beans, separated by commas.
             Useful for when using maven and jetty:run (version 6) or tomcat:run
        </description>
        <param-name>org.apache.myfaces.annotation.SCAN_PACKAGES</param-name>
        <param-value>eu.dedalus</param-value>
    

.5 jsf-api e jsf-impl WEB-INF/lib.

.6 [ECLIPSE ONLY] myfaces.api myfaces-impl M2REPO jsf-api jsf-impl.

https://stackoverflow.com/users/814956/lu4242!

+3

Source: https://habr.com/ru/post/1526129/


All Articles