title: CDI: Exception because disposal method dont see produce method
body: <p>I am following some tutorials to get used to CDI, by the way I am having a hard time. Actually I have an Factory class responsable for creating instances of the EntityManager to be used by CDI and also have an disposal method that is suposed to close the connection started by the manager when the requistion ends. The problem is that my disposal method aparently can't see my produces method and that is explicit in this error message that comes up with Tomcat 7.</p>
  
  <p>SEVERE: Exception sending context initialized event to listener instance of class org.jboss.weld.environment.servlet.Listener
  org.jboss.weld.exceptions.DefinitionException: WELD-001424 The following disposal methods were declared but did not resolve to a producer method:  [Disposer method [[method] public br.com.logtec.producer.DataRepositoryProducer.finalize(EntityManager)]]
      at org.jboss.weld.bootstrap.Validator.validateDisposalMethods(Validator.java:541)
      at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:371)
      at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:380)
      at org.jboss.weld.environment.servlet.Listener.contextInitialized(Listener.java:182)
      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4992)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5490)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
      at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
      at java.util.concurrent.FutureTask.run(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)</p>
  
  <p>This is my class:</p>
  
  <p>@Singleton
  public class DataRepositoryProducer {</p>
  
  <pre><code>private static EntityManagerFactory factory;
  
  @Produces
  public EntityManagerFactory getEntityManagerFactory() {
      if (factory == null) {
          factory = Persistence.createEntityManagerFactory("pu");
      }
      return factory;
  }
  
  @Produces
  @DataRepository
  @RequestScoped
  public EntityManager produceEntityManager() {
      return getEntityManagerFactory().createEntityManager();
  }
  
  public void finalize(@Disposes EntityManager manager) {
      manager.close();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Any clues?</p>