I'm not getting the CDI to work, I'm using the maven tomcat7 plugin.
The beans.xml is created and in the WEB-INF folder, context.xml is also in the META-INF folder, I also put the dependencies of the CDI, both implementation and specification, also follows the code of the bean with the imports of the cdi and a jsf page.
Follow the code
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}"/>
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