Problemas com o DaoInterceptor

2 respostas
higornucci

Estou com problemas na hora de fazer a listagem ou adição de usuários. A classe e o erro que o tomcat exibe são os seguintes:

import org.vraptor.Interceptor;
import org.vraptor.LogicException;
import org.vraptor.LogicFlow;
import org.vraptor.annotations.Out;
import org.vraptor.view.ViewException;

import br.com.caelum.lojavirtual.dao.DaoFactory;

public class DaoInterceptor implements Interceptor{
	
	private final DaoFactory factory = new DaoFactory();
	
	public void intercept(LogicFlow flow) throws LogicException, ViewException {

		flow.execute();
		
		if (factory.hasTransaction()) {
			factory.rollback();
		}
		factory.close();
	}
	
	@Out(key="br.com.caelum.lojavirtual.dao.DaoFactory")
	public DaoFactory getFactory() {
		return factory;
	}
}
exception

javax.servlet.ServletException: Unable to instantiate using public br.com.caelum.lojavirtual.logic.DaoInterceptor()
	org.vraptor.http.DefaultDispatcher.dispatch(DefaultDispatcher.java:55)
	org.vraptor.VRaptorServlet.service(VRaptorServlet.java:48)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

root cause

org.vraptor.interceptor.InterceptorInstantiationException: Unable to instantiate using public br.com.caelum.lojavirtual.logic.DaoInterceptor()
	org.vraptor.interceptor.InterceptorDealer.poll(InterceptorDealer.java:68)
	org.vraptor.core.InterceptorsLogicFlow.execute(InterceptorsLogicFlow.java:58)
	org.vraptor.interceptor.FlashScopeInterceptor.intercept(FlashScopeInterceptor.java:22)
	org.vraptor.core.InterceptorsLogicFlow.execute(InterceptorsLogicFlow.java:72)
	org.vraptor.interceptor.RegisterAttributesInteceptor.intercept(RegisterAttributesInteceptor.java:47)
	org.vraptor.core.InterceptorsLogicFlow.execute(InterceptorsLogicFlow.java:72)
	org.vraptor.core.VRaptorExecution.execute(VRaptorExecution.java:97)
	org.vraptor.core.DefaultController.execute(DefaultController.java:46)
	org.vraptor.http.DefaultDispatcher.dispatch(DefaultDispatcher.java:44)
	org.vraptor.VRaptorServlet.service(VRaptorServlet.java:48)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

root cause

org.vraptor.component.ComponentInstantiationException: Unable to instantiate using public br.com.caelum.lojavirtual.logic.DaoInterceptor()
	org.vraptor.component.ComponentConstructor.newInstance(ComponentConstructor.java:45)
	org.vraptor.interceptor.InterceptorType.newInstance(InterceptorType.java:66)
	org.vraptor.interceptor.InterceptorDealer.poll(InterceptorDealer.java:62)
	org.vraptor.core.InterceptorsLogicFlow.execute(InterceptorsLogicFlow.java:58)
	org.vraptor.interceptor.FlashScopeInterceptor.intercept(FlashScopeInterceptor.java:22)
	org.vraptor.core.InterceptorsLogicFlow.execute(InterceptorsLogicFlow.java:72)
	org.vraptor.interceptor.RegisterAttributesInteceptor.intercept(RegisterAttributesInteceptor.java:47)
	org.vraptor.core.InterceptorsLogicFlow.execute(InterceptorsLogicFlow.java:72)
	org.vraptor.core.VRaptorExecution.execute(VRaptorExecution.java:97)
	org.vraptor.core.DefaultController.execute(DefaultController.java:46)
	org.vraptor.http.DefaultDispatcher.dispatch(DefaultDispatcher.java:44)
	org.vraptor.VRaptorServlet.service(VRaptorServlet.java:48)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

root cause

java.lang.reflect.InvocationTargetException
	sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	java.lang.reflect.Constructor.newInstance(Unknown Source)
	org.vraptor.component.ComponentConstructor.newInstance(ComponentConstructor.java:43)
	org.vraptor.interceptor.InterceptorType.newInstance(InterceptorType.java:66)
	org.vraptor.interceptor.InterceptorDealer.poll(InterceptorDealer.java:62)
	org.vraptor.core.InterceptorsLogicFlow.execute(InterceptorsLogicFlow.java:58)
	org.vraptor.interceptor.FlashScopeInterceptor.intercept(FlashScopeInterceptor.java:22)
	org.vraptor.core.InterceptorsLogicFlow.execute(InterceptorsLogicFlow.java:72)
	org.vraptor.interceptor.RegisterAttributesInteceptor.intercept(RegisterAttributesInteceptor.java:47)
	org.vraptor.core.InterceptorsLogicFlow.execute(InterceptorsLogicFlow.java:72)
	org.vraptor.core.VRaptorExecution.execute(VRaptorExecution.java:97)
	org.vraptor.core.DefaultController.execute(DefaultController.java:46)
	org.vraptor.http.DefaultDispatcher.dispatch(DefaultDispatcher.java:44)
	org.vraptor.VRaptorServlet.service(VRaptorServlet.java:48)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

root cause

java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
	br.com.caelum.lojavirtual.dao.DaoFactory.<init>(DaoFactory.java:14)
	br.com.caelum.lojavirtual.logic.DaoInterceptor.<init>(DaoInterceptor.java:13)
	sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	java.lang.reflect.Constructor.newInstance(Unknown Source)
	org.vraptor.component.ComponentConstructor.newInstance(ComponentConstructor.java:43)
	org.vraptor.interceptor.InterceptorType.newInstance(InterceptorType.java:66)
	org.vraptor.interceptor.InterceptorDealer.poll(InterceptorDealer.java:62)
	org.vraptor.core.InterceptorsLogicFlow.execute(InterceptorsLogicFlow.java:58)
	org.vraptor.interceptor.FlashScopeInterceptor.intercept(FlashScopeInterceptor.java:22)
	org.vraptor.core.InterceptorsLogicFlow.execute(InterceptorsLogicFlow.java:72)
	org.vraptor.interceptor.RegisterAttributesInteceptor.intercept(RegisterAttributesInteceptor.java:47)
	org.vraptor.core.InterceptorsLogicFlow.execute(InterceptorsLogicFlow.java:72)
	org.vraptor.core.VRaptorExecution.execute(VRaptorExecution.java:97)
	org.vraptor.core.DefaultController.execute(DefaultController.java:46)
	org.vraptor.http.DefaultDispatcher.dispatch(DefaultDispatcher.java:44)
	org.vraptor.VRaptorServlet.service(VRaptorServlet.java:48)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

root cause

java.lang.ClassNotFoundException: org.hibernate.cfg.Configuration
	org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1386)
	org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1232)
	java.lang.ClassLoader.loadClassInternal(Unknown Source)
	br.com.caelum.lojavirtual.dao.DaoFactory.<init>(DaoFactory.java:14)
	br.com.caelum.lojavirtual.logic.DaoInterceptor.<init>(DaoInterceptor.java:13)
	sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	java.lang.reflect.Constructor.newInstance(Unknown Source)
	org.vraptor.component.ComponentConstructor.newInstance(ComponentConstructor.java:43)
	org.vraptor.interceptor.InterceptorType.newInstance(InterceptorType.java:66)
	org.vraptor.interceptor.InterceptorDealer.poll(InterceptorDealer.java:62)
	org.vraptor.core.InterceptorsLogicFlow.execute(InterceptorsLogicFlow.java:58)
	org.vraptor.interceptor.FlashScopeInterceptor.intercept(FlashScopeInterceptor.java:22)
	org.vraptor.core.InterceptorsLogicFlow.execute(InterceptorsLogicFlow.java:72)
	org.vraptor.interceptor.RegisterAttributesInteceptor.intercept(RegisterAttributesInteceptor.java:47)
	org.vraptor.core.InterceptorsLogicFlow.execute(InterceptorsLogicFlow.java:72)
	org.vraptor.core.VRaptorExecution.execute(VRaptorExecution.java:97)
	org.vraptor.core.DefaultController.execute(DefaultController.java:46)
	org.vraptor.http.DefaultDispatcher.dispatch(DefaultDispatcher.java:44)
	org.vraptor.VRaptorServlet.service(VRaptorServlet.java:48)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

Alguém sabe o que pode estar errado?

2 Respostas

mateusprado

Biom pelo oq percebi, vc esta usando a aplicação de exemplo do VRaptor, ou criou uma seguindo os modelos.

  • De uma olhada nos jars de sua aplicação;
  • Verifique o arquivo hibernate.cfg.xml no diretorio src/
java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration

[ ]s,

higornucci

Ele ta certinho, a senha, o loguin e o nome do schema tambem. E a classe HibernateUtil ta chamando ele no local certo.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
      
    <!-- properties -->
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver
        </property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/lojavirtual
        </property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect
        </property>
    <property name="hibernate.show_sql">true
        </property>
    <property name="hibernate.format_sql">true
    	</property>
    <property name="hibernate.connection.username">root
        </property>
    <property name="hibernate.connection.password">root
        </property>
    <!-- mapping classes -->
    	<mapping class="br.com.caelum.lojavirtual.modelo.Usuario"/>

  </session-factory>
</hibernate-configuration>
package br.com.caelum.lojavirtual.util;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {

	private static SessionFactory factory;

	static {
		Configuration conf = new AnnotationConfiguration();
		conf.configure("/br/com/caelum/lojavirtual/util/hibernate.cfg.xml");
		factory = conf.buildSessionFactory();
	}
	
	public static Session getSession() {
		return factory.openSession();
	}

}

não sei o que pode estar errado.

Criado 24 de março de 2009
Ultima resposta 24 de mar. de 2009
Respostas 2
Participantes 2