** Boa noite. Estou seguindo o curso de JSF desde o primeiro módulo e portanto tenho evoluído o projeto em que iniciei ao invés de baixar um projeto a cada capitulo.
Porém, estou tendo alguns problemas, em especifico com o CDI, porém, tentarei resolver-los por partes.
O tomcat que estou usando é o 8 ao inicia-lo exibe o seguinte erro: **
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/livraria]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) ... 6 more Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type EntityManager with qualifiers @Default at injection point [BackedAnnotatedField] @Inject private br.com.caelum.livraria.tx.GerenciaTransacao.entityManager at br.com.caelum.livraria.tx.GerenciaTransacao.entityManager(GerenciaTransacao.java:0)
at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:355) at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:277) at org.jboss.weld.bootstrap.Validator.validateInterceptor(Validator.java:532) at org.jboss.weld.bootstrap.ConcurrentValidator$2.doWork(ConcurrentValidator.java:81) at org.jboss.weld.bootstrap.ConcurrentValidator$2.doWork(ConcurrentValidator.java:79) at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:62) at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:55) ... 4 more
Minha classe:
package br.com.caelum.livraria.tx;
import java.io.Serializable;
import javax.inject.Inject;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;
import javax.persistence.EntityManager;
@transacional
@Interceptor
public class GerenciaTransacao implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Inject
private EntityManager entityManager;
@AroundInvoke
public Object executa(InvocationContext contexto) throws Exception{
entityManager.getTransaction().begin();
Object result = contexto.proceed();
entityManager.getTransaction().commit();
return result;
}
}
Minha @interface
package br.com.caelum.livraria.tx;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.interceptor.InterceptorBinding;
@InterceptorBinding
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface transacional {
}
E, acho que a criação do EntityManager também possa ser relevante
package br.com.caelum.livraria.dao;
import java.io.Serializable;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Model;
import javax.enterprise.inject.Produces;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class JPAUtil implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private static EntityManagerFactory emf = Persistence
.createEntityManagerFactory("livraria");
@Produces
@RequestScoped
public EntityManager getEntityManager() {
return emf.createEntityManager();
}
public void close(@Disposes EntityManager em) {
em.close();
}
}
Agradeço desde já!