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.
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)
This is my class:
@Singleton public class DataRepositoryProducer {
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();
}
}
Any clues?
Following the advice of @Robert Panzer I was able to solve the problem adding my @DataRepository after the @Disposes annotation in the disposal method.