CDI is not working with Tomcat7 by Maven + JSF

Asked

Viewed 228 times

0

I’m not able to make CDI work, I’m using the tomcat7 plugin from Maven.

Beans.xml is created and in the WEB-INF folder, context.xml is also in the META-INF folder, I also put the CDI dependencies, both implementation and specification, also follows the bean code with the cdi Imports and a jsf page.

Follows the code

Beans.xml

<!-- webapp/WEB-INF/beans.xml -->
<beans>
</beans>

xml context.

pom.xml

<dependency>
    <groupId>javax.enterprise</groupId>
    <artifactId>cdi-api</artifactId>
    <version>1.2</version>
    <scope>provided</scope>
</dependency>

<dependency>
    <groupId>org.jboss.weld.servlet</groupId>
    <artifactId>weld-servlet</artifactId>
    <version>2.3.2.Final</version>
</dependency>

Meubean.java

import javax.faces.view.ViewScoped;
import javax.inject.Named;
import java.io.Serializable;

@ViewScoped
@Named
public class MeuBean implements Serializable {

    private Usuario usuario = new Usuario();

    public Usuario getUsuario() {
        return usuario;
    }

    public void setUsuario(Usuario usuario) {
        this.usuario = usuario;
    }

    public void testePrinta(){
        System.out.println(usuario);
    }

}

login.xhtml

<p:inputText placeholder="Nome" value="#{meuBean.usuario.username}" />
<p:password placeholder="Senha" value="#{meuBean.usuario.senha}" />
<p:commandButton value="Login" action="#{meuBean.printa}"/>

The following WELD logs appear:

INFO: WELD-ENV-001008: Initialize Weld using ServletContainerInitializer
nov 03, 2017 3:29:59 PM org.jboss.weld.bootstrap.WeldStartup <clinit>
INFO: WELD-000900: 2.3.2 (Final)
nov 03, 2017 3:29:59 PM org.jboss.weld.environment.deployment.discovery.DiscoveryStrategyFactory create
INFO: WELD-ENV-000020: Using jandex for bean discovery
nov 03, 2017 3:30:00 PM org.jboss.weld.bootstrap.WeldStartup startContainer
INFO: WELD-000101: Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
nov 03, 2017 3:30:00 PM org.jboss.weld.event.ExtensionObserverMethodImpl checkRequiredTypeAnnotations
INFO: WELD-000411: Observer method [BackedAnnotatedMethod] com.sun.jersey.server.impl.cdi.CDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType<T>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
nov 03, 2017 3:30:00 PM org.jboss.weld.environment.tomcat.TomcatContainer initialize
INFO: WELD-ENV-001100: Tomcat 7+ detected, CDI injection will be available in Servlets, Filters and Listeners.
nov 03, 2017 3:30:01 PM com.sun.faces.config.ConfigureListener contextInitialized

1 answer

0


Just move the file beans.xml to the folder

src/main/resources/META-INF

Browser other questions tagged

You are not signed in. Login or sign up in order to post.