2 Replies Latest reply on Jun 11, 2018 12:00 PM by Luca Stancapiano

    Missing injection using java 9 or 10

    Luca Stancapiano Expert

      Hi all, I'm using WIldFly 12 with java 10. In my webapp I have this simple bean:

       

      @Named

      public class MyBean {

        public String getOperation() {

            return "ok";

        }

      }

       

      I would call it injecting it in my JSF xhtml page:

       

      <div xmlns="http://www.w3.org/1999/xhtml"

        xmlns:ui="http://xmlns.jcp.org/jsf/facelets"

        xmlns:h="http://xmlns.jcp.org/jsf/html">

       

        <ui:composition>

        <h:outputText value="#{myBean.operation}" />

        </ui:composition>

      </div>

       

      In the WEB-INF folder I have a beans.xml:

       

       

      <?xml version="1.0" encoding="UTF-8"?>

      <beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee

                                 http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"

        version="1.1" bean-discovery-mode="all">

      </beans>

       

      and a web.xml:

       

       

      <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"

        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"

        version="3.1">

        <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>

       

      </web-app>

       

      Here my pom.xml with the javaee7 dependencies:

       

       

      <project xmlns="http://maven.apache.org/POM/4.0.0"

        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

      ...

       

        <properties>

        <maven.compiler.source>10</maven.compiler.source>

        <maven.compiler.target>10</maven.compiler.target>

        </properties>

       

        <dependencies>

             <dependency>

                       <groupId>org.jboss.spec</groupId>

                       <artifactId>jboss-javaee-7.0</artifactId>

                       <version>1.1.1.Final</version>

                       <type>pom</type>

                       <scope>provided</scope>

             </dependency>

        </dependencies>

      </project>

       

      When I execute the webapp the bean is not resolved so I have a white page.

      If I update the pom.xml changing the java properties passing to java 9 so:

       

        <properties>

                  <maven.compiler.source>9</maven.compiler.source>

                  <maven.compiler.target>9</maven.compiler.target>

        </properties>

       

      I have the same problem. If I change it using java 1.8 so:

       

        <properties>

                  <maven.compiler.source>1.8</maven.compiler.source>

                  <maven.compiler.target>1.8</maven.compiler.target>

        </properties>

       

      It works and I see the "ok" value in the browser page. What is the problem?

       

      Here you can find the complete webapp: https://github.com/flashboss/search-java9-wildfly12-bughttps://github.com/flashboss/search-java9-wildfly12-bug