Problem with JSF2 + CDI + Tomcat

-1

Personal speech,
I'm working with JSF and I've packed here. I have a simple project for now, with a page with a form that has an enum attribute on it, ie when the page loads it has a selectItems there that should come loaded from the enum. Home Using @ManagedBean and JSF scope this works normally. But when I try to migrate to CDI, the enum stops loading. I have already tried trying to write a simple attribute on the screen and also will not. From what I saw, it should be simple, but I have already followed several tutorials and failed miserably. Of course it must be stupid of me, but I can not see what it is. In the console does not appear any error msg and the page loads normally, it only brings nothing of the Managed Bean. I have already named named in the bean, enum, and nothing. So, what's the catch?

POM.xml

<dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.faces</artifactId>
        <version>${jsf-api.version}</version>
    </dependency>

    <!-- Servelet -->
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>${javaee-web-api.version}</version>
        <type>jar</type>
    </dependency>
<dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <version>2.0</version>
    </dependency>

    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.2.17</version>
    </dependency>
//Outras dependências (JPA, Hibernate, Wildfly) 

WEB-INF / 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="2.0" bean-discovery-mode="all">
</beans>

WEB-INF / context.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context>
    <Resource name="BeanManager" 
             auth="Container"
            type="javax.enterprise.inject.spi.BeanManager" 
    factory="org.jboss.weld.resources.ManagerObjectFactory"/</Context>

MB

@Named //javax.inject.Named
@RequestScoped //javax.enterprise.context.RequestScoped
public class CadastroQuestaoMB implements Serializable
{
    private static final long serialVersionUID = 1L;

    @Inject
    Questao questao;
    ...
    
asked by anonymous 22.10.2018 / 21:22

1 answer

1

You are only using cdi api. You need the implementation too, since tomcat does not implement cdi.

<dependency>
    <groupId>org.jboss.weld.servlet</groupId>
    <artifactId>weld-servlet</artifactId>
    <version>2.4.8.Final</version>
</dependency>
    
22.10.2018 / 23:37