title: Problems with CDI - ( Weld + TomCat7 + JSF )
body: <p>I'm starting a project with CDI using weld, and am getting the following error when I try to injection:</p>
  
  <pre><code>@Inject
  private UserRepository repository;
  </code></pre>
  
  <p>Console:</p>
  
  <pre><code>INFO: Starting Servlet Engine: Apache Tomcat/7.0.12
  13:16:22,859  INFO servletWeldServlet:57 - WELD-ENV-001008: Initialize Weld using ServletContainerInitializer
  13:16:22,875  INFO Version:151 - WELD-000900: 2.2.5 (Final)
  13:16:22,906  INFO Bootstrap:206 - WELD-000101: Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
  13:16:22,937  WARN Interceptor:47 - WELD-001700: Interceptor annotation class javax.ejb.PostActivate not found, interception based on it is not enabled
  13:16:22,937  WARN Interceptor:47 - WELD-001700: Interceptor annotation class javax.ejb.PrePassivate not found, interception based on it is not enabled
  13:16:23,046  INFO servletTomcat:45 - WELD-ENV-001100: Tomcat 7+ detected, CDI injection will be available in Servlets, Filters and Listeners.
  org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type UserRepository with qualifiers @Default
    at injection point [BackedAnnotatedField] @Inject private br.com.controllers.UserController.repository
    at br.com.controllers.UserController.repository(UserController.java:0)
  
      at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:372)
      at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:293)
      at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:134)
      at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:167)
      at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:531)
      at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:68)
      at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:66)
      at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60)
      at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53)
      at java.util.concurrent.FutureTask.run(FutureTask.java:262)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p><strong>EntityManagerFactory.java</strong></p>
  
  <pre><code>package br.com.util;
  
  import javax.enterprise.inject.Disposes;
  import javax.enterprise.inject.Produces;
  import javax.persistence.EntityManager;
  import javax.persistence.PersistenceContext;
  
  public class EntityManagerFactory {
  
      @PersistenceContext(unitName="default")
      private EntityManager em;
  
      @Produces
      public EntityManager create() {
          return em;
      }
  
      public void close(@Disposes EntityManager em) {
          em.close();
      }
  
  }
  </code></pre>
  
  <p><strong>Repository.java</strong></p>
  
  <pre><code>import java.io.Serializable;
  import java.lang.reflect.ParameterizedType;
  import java.util.List;
  
  import javax.inject.Inject;
  import javax.persistence.EntityManager;
  import javax.persistence.TypedQuery;
  
  public abstract class Repository&lt;T, I extends Serializable&gt; {
  
  
      @Inject
      protected final EntityManager entityManager;
      protected final Class&lt;T&gt; clazz;
  
      protected Repository(EntityManager entityManager) {
  
          this.entityManager = entityManager;
          @SuppressWarnings("unchecked")
          Class&lt;T&gt; clazz = (Class&lt;T&gt;) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
          this.clazz = clazz;
  
      }
  
      public void refresh(T entity){
          entityManager.refresh(entity);  
      }
  
      public void create(T entity) {
          entityManager.persist(entity);  
      }
  
      public T update(T entity) {
          return entityManager.merge(entity);
      }
  
      public void destroy(T entity) {
          entityManager.remove(entity);
      }
  
      public T find(I id) {
          return entityManager.find(clazz, id);
      }
  
      public List&lt;T&gt; findAll() {
  
          TypedQuery&lt;T&gt; query = entityManager.createQuery("FROM " + clazz.getName() ,clazz);    
          List&lt;T&gt; resultList = query.getResultList();
          return resultList;    
      }
  
  
  
  }
  </code></pre>
  
  <p><strong>UserRepositoryImpl.java</strong></p>
  
  <pre><code>package br.com.repositories;
  
  
  import javax.persistence.EntityManager;
  import javax.transaction.Transactional;
  
  import br.com.models.User;
  
  
  @Transactional
  public class UserRepositoryImpl extends Repository&lt;User, Long &gt;implements UserRepository {
  
      protected UserRepositoryImpl(EntityManager entityManager) {
          super(entityManager);
      }
  
  
  }
  </code></pre>
  
  <p><strong>UserController.java</strong></p>
  
  <pre><code>package br.com.controllers;
  
  import javax.annotation.PostConstruct;
  import javax.enterprise.context.RequestScoped;
  import javax.inject.Inject;
  import javax.inject.Named;
  
  import br.com.repositories.UserRepository;
  
  
  
  @Named("userController")  
  @RequestScoped  
  public class UserController {
  
      @Inject
      private UserRepository repository;
  
      UserController(){
  
      }
  
      @PostConstruct
      public void init(){
          System.out.println("started");
      }
  
      public String getMessage(){
          return "test";
      }
  
      public void create(){
          System.out.println("test method");
      }
  
  }
  </code></pre>
  
  <p><strong>META-INF/beans.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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"&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>META-INF/context.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Context&gt;
  &lt;Manager pathname=""/&gt; &lt;!-- disables storage of sessions across restarts --&gt;
  &lt;Resource name="BeanManager"
  auth="Container"
  type="javax.enterprise.inject.spi.BeanManager"
  factory="org.jboss.weld.resources.ManagerObjectFactory"/&gt;
  &lt;/Context&gt;
  </code></pre>
  
  <p><strong>WEB-INF/web.xml</strong></p>
  
  <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"&gt;
        &lt;display-name&gt;wochenbericht&lt;/display-name&gt;
  
       &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;index.jsf&lt;/welcome-file&gt;
        &lt;/welcome-file-list&gt;
  
        &lt;!-- CDI - WELD --&gt;
         &lt;listener&gt;
         &lt;listener-class&gt;org.jboss.weld.environment.servlet.Listener&lt;/listener-class&gt;
         &lt;/listener&gt;
  
          &lt;resource-env-ref&gt;
          &lt;resource-env-ref-name&gt;BeanManager&lt;/resource-env-ref-name&gt;
              &lt;resource-env-ref-type&gt;
                 javax.enterprise.inject.spi.BeanManager
              &lt;/resource-env-ref-type&gt;
          &lt;/resource-env-ref&gt;
  
  
        &lt;!-- JSF --&gt;
        &lt;servlet&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
        &lt;/servlet&gt;
        &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;*.jsf&lt;/url-pattern&gt;
        &lt;/servlet-mapping&gt;
  
  
        &lt;!-- SESSION TIMEOUT --&gt;
        &lt;session-config&gt;
           &lt;session-timeout&gt;30&lt;/session-timeout&gt;
        &lt;/session-config&gt; 
  
        &lt;!-- CONTEXT LOCAL --&gt;
        &lt;context-param&gt;
            &lt;param-name&gt;javax.faces.STATE_SAVING_METHOD&lt;/param-name&gt;
            &lt;param-value&gt;client&lt;/param-value&gt;
        &lt;/context-param&gt; 
  
        &lt;context-param&gt;
            &lt;param-name&gt;javax.faces.FACELETS_REFRESH_PERIOD&lt;/param-name&gt;
            &lt;param-value&gt;2&lt;/param-value&gt;
        &lt;/context-param&gt; 
  
        &lt;context-param&gt;
          &lt;param-name&gt;javax.faces.WEBAPP_RESOURCES_DIRECTORY&lt;/param-name&gt;
          &lt;param-value&gt;/assets&lt;/param-value&gt; 
        &lt;/context-param&gt;
  
        &lt;context-param&gt;
          &lt;param-name&gt;javax.faces.PROJECT_STAGE&lt;/param-name&gt;
          &lt;param-value&gt;Development&lt;/param-value&gt;
        &lt;/context-param&gt;
  
        &lt;!--  SECURITY SETTINGS --&gt;
        &lt;security-constraint&gt;
          &lt;display-name&gt;Restrict direct access to XHTML files&lt;/display-name&gt;
          &lt;web-resource-collection&gt;
              &lt;web-resource-name&gt;XHTML files&lt;/web-resource-name&gt;
              &lt;url-pattern&gt;*.xhtml&lt;/url-pattern&gt;
          &lt;/web-resource-collection&gt;
          &lt;auth-constraint /&gt;
        &lt;/security-constraint&gt;
  </code></pre>
  
  <p><strong>My Libs:</strong></p>
  
  <pre><code>antlr-2.7.7.jar
  aopalliance.jar
  c3p0-0.9.1.jar
  cdi-api-1.1.jar
  dom4j-1.6.1.jar
  EasyCriteria-3.1.0.jar
  hibernate-c3p0-4.3.6.Final.jar
  hibernate-commons-annotations-4.0.5.Final.jar
  hibernate-core-4.3.6.Final.jar
  hibernate-entitymanager-4.3.5.Final.jar
  hibernate-jpa-2.1-api-1.0.0.Final.jar
  hibernate-validator-4.3.0.Final.jar
  javassist-3.18.1-GA.jar
  javax.inject.jar
  jboss-logging-3.1.3.GA.jar
  jboss-logging-annotations-1.2.0.Beta1.jar
  jboss-transaction-api_1.2_spec-1.0.0.Final.jar
  jsf-api-2.2.8.jar
  jsf-impl-2.2.8.jar
  log4j-1.2.16.jar
  postgresql-9.2-1003.jdbc4.jar
  slf4j-api-1.6.6.jar
  slf4j-jdk14-1.6.6.jar
  slf4j-log4j12-1.6.1.jar
  validation-api-1.0.0.GA.jar
  weld-se-core-2.2.5.Final.jar
  weld-servlet-2.2.5.Final.jar
  weld-servlet-core-2.2.5.Final.jar
  </code></pre>
  
  <p>Can anyone help me? thank you!</p>