0

Não estou conseguindo fazer o CDI funcionar, estou utilizando o plugin do tomcat7 do maven.

O beans.xml está criado e na pasta WEB-INF, o context.xml também e está na pasta META-INF, também coloquei as dependências do CDI, tanto implementação como especificação, também segue o código do bean com os imports do cdi e uma página jsf.

Segue o código

beans.xml

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

context.xml

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}"/>

Os seguintes logs do WELD aparecem:

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

0

É só mover o arquivo beans.xml para a pasta

src/main/resources/META-INF

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .