Problemas integração VRaptor + Spring + Hibernate

25 respostas
R

Pessoal,

Baixei o VRaptor 3 e estou tentando plugar com Spring e Hibernate, mas vira e mexe da umas exceptions lokas.
Gostaria de saber se estou fazendo algo errado.

Segue minhas configurações:
jdbc.properties:

database.driver=oracle.jdbc.driver.OracleDriver
database.url=jdbc:oracle:thin:@blablabla:1521:blabla
database.user=recru
database.pass=recru#01
database.initConnections=1
database.maxActive=10
database.maxIdle=5
database.removeAbandoned=true

applicationContext.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
       xmlns:context="http://www.springframework.org/schema/context" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xmlns:cxf="http://cxf.apache.org/core" 
       xmlns:jaxrs="http://cxf.apache.org/jaxrs" 
       xmlns:jaxws="http://cxf.apache.org/jaxws" 
       xmlns:tx="http://www.springframework.org/schema/tx" 
       xmlns:p="http://www.springframework.org/schema/p" 
       xsi:schemaLocation=" 
       http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
       http://www.springframework.org/schema/context 
       http://www.springframework.org/schema/context/spring-context-3.0.xsd 
       http://www.springframework.org/schema/tx 
       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
       http://www.springframework.org/schema/aop 
       http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
           
           <!-- ****** Inicio dos arquivos de configuracao ****** -->
           <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
              <property name="locations">
                 <list>  
                    <value>/WEB-INF/jdbc.properties</value>
                 </list>  
              </property>  
           </bean>
           
           <!-- Bean com as configuracoes de conexao com o banco, utilizado CommonsDBCP da Apache para gerenciar nosso pool de conexão -->
           <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
               <property name="driverClassName" value="${database.driver}" />  
               <property name="url"             value="${database.url}" />  
               <property name="username"        value="${database.user}" />  
               <property name="password"        value="${database.pass}" />  
               <property name="initialSize"     value="${database.initConnections}" />  
               <property name="maxActive"       value="${database.maxActive}" />
               <property name="maxIdle"         value="${database.maxIdle}" />
               <property name="removeAbandoned" value="${database.removeAbandoned}" />
           </bean>                      
           
           <!-- Fabrica de sessoes -->
           <bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
               <property name="dataSource">  
                   <ref local="dataSource" />  
               </property>
               
               <property name="annotatedClasses">  
                   <list>  
                       <value>br.com.vraptor.vo.PessoaVo</value>
                   </list>
               </property>
               
               <property name="hibernateProperties">
                   <props>
                       <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
                       <prop key="hibernate.show_sql">true</prop>
                       <prop key="hibernate.format_sql">true</prop>
                   </props>  
               </property>  
           </bean>
                                 
           <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
                <property name="sessionFactory" ref="hibernateSessionFactory" />
           </bean>
           
           <tx:annotation-driven transaction-manager="transactionManager" />
           
           <!-- Faz a indentificacao dos beans anotados com @Service, @Repository e @Controller -->
           <context:component-scan base-package="br.com.vraptor.controller" />
           <context:component-scan base-package="br.com.vraptor.dao.hibernate" />
           
           <!-- Habilita a configuracao de beans via anotacoes -->
           <context:annotation-config />
</beans>

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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_2_5.xsd" id="WebApp_ID" version="2.5">
        
    <display-name>vraptor</display-name>

    <context-param>
        <!-- Nao mexer configuracao do vraptor -->
        <param-name>br.com.caelum.vraptor.packages</param-name>
        
        <!-- Meus controllers -->
        <param-value>br.com.vraptor.controller</param-value>
    </context-param>
    
    <filter>
        <filter-name>vraptor</filter-name>
        <filter-class>br.com.caelum.vraptor.VRaptor</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>vraptor</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>

    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
    
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
</web-app>

Minha IndexController onde estou tentando injetar meu objeto PessoaHibernateDao:

@Resource
@Service
public class IndexController
{    
    private PessoaHibernateDao pessoaHibernateDao;
 
    @Autowired
    public void setPessoaHibernateDao(PessoaHibernateDao pessoaHibernateDao)
    {
        this.pessoaHibernateDao = pessoaHibernateDao;
    }
    
    @Path("/")
    public List<PessoaVo> index()
    {
        List<PessoaVo> pessoaList = pessoaHibernateDao.findPessoasWithChapa();
        
        for (PessoaVo vo : pessoaList)
        {
            System.out.println(vo.getNome());
        }
        
        return pessoaList;
    }
}

PessoaHibernateDao:

@Repository
public class PessoaHibernateDao extends HibernateDaoGenerico<PessoaVo, Long> implements IPessoaDao
{
    // Injetando SessionFactory
    private SessionFactory sessionFactory;
    
    @Autowired
    public void setSessionFactory(SessionFactory sessionFactory)
    {
        this.sessionFactory = sessionFactory;
    }
    
    public PessoaHibernateDao()
    {
        super(PessoaVo.class);
        super.setSessionFactoty(this.sessionFactory);
    }
    
    @Override
    @Transactional(readOnly=true)
    public List<PessoaVo> findPessoasWithChapa()
    {  
        return findByCriteria(Expression.isNotNull("chapa"), Expression.ne("chapa", 0L));
    }
}

Quando mando contruir a aplicação não é gerado nenhum problema, mas nos logs do apache ou quando tento acesso o index mapeado para o /, esta dando o seguinte erro:

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void br.com.vraptor.controller.IndexController.setPessoaHibernateDao(br.com.vraptor.dao.hibernate.PessoaHibernateDao); nested exception is java.lang.IllegalArgumentException: argument type mismatch
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:605)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:280)
... 24 more
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:598)
... 26 more
17/06/2011 12:07:28 org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext

O que pode estar ocorrendo?
Alguém poderia me ajudar por gentileza?

[]'s
Daniel Razah.
Bem dito seja o ETERNO nosso D'US.

25 Respostas

Lucas_Cavalcanti

edita a sua mensagem anterior colocando os códigos entre e , por favor

R

Coloquei mas não vi diferença na visualização.

[]'s
Daniel Razah.

R

Agora foi! rs…

[]'s
Daniel Razah.

Lucas_Cavalcanti

bom, deve ser algum problema do guj…

algum motivo pra vc estar usando as anotações do VRaptor e do Spring ao mesmo tempo? geralmente só as do VRaptor são o suficiente, principalmente na última versão.

tire o @Service do Controller, receba o dao no construtor pela interface IPessoaDao e tire o setter. Isso deve fazer tudo funcionar sem problemas…

Lucas_Cavalcanti

outra coisa, se os seus controllers não estão dentro de um jar você não precisa da configuração de packages do VRaptor, pode retirar do web.xml

R

Lucas Cavalcanti:
bom, deve ser algum problema do guj…

algum motivo pra vc estar usando as anotações do VRaptor e do Spring ao mesmo tempo? geralmente só as do VRaptor são o suficiente, principalmente na última versão.

tire o @Service do Controller, receba o dao no construtor pela interface IPessoaDao e tire o setter. Isso deve fazer tudo funcionar sem problemas…

Quando ele fizer a injeção será pelo spring?
Porque quero usar spring somente para gerenciar minhas sessions.

R
Lucas Cavalcanti:
bom, deve ser algum problema do guj...

algum motivo pra vc estar usando as anotações do VRaptor e do Spring ao mesmo tempo? geralmente só as do VRaptor são o suficiente, principalmente na última versão.

tire o @Service do Controller, receba o dao no construtor pela interface IPessoaDao e tire o setter. Isso deve fazer tudo funcionar sem problemas...

As injeções agora estão funcionando. O que esta ocorrendo é um NullPointerException ao chamar o método findByCriteria da classe HibernateDaoGenerico.
Não sei se esta tudo configurando da maneira certa.

Segue o código da mesma:

/**
 *
 * @author daniel.rfonseca
 */
@SuppressWarnings("unchecked")
public class HibernateDaoGenerico<T, ID extends Serializable> implements IGenericDAO<T, ID>
{        
    private static Log LOG = LogFactory.getLog(HibernateDaoGenerico.class);
            
    // Classe que sera persistida.  
    private Class<T> persistentClass;
    
    public  Class<T> getPersistentClass()
    {
        return this.persistentClass;
    }        
    
    public HibernateDaoGenerico() {}
        
    public HibernateDaoGenerico(Class<T> vo)
    {
        this.persistentClass = vo;
    }
    
    private SessionFactory sessionFactory;
    
    public void setSessionFactoty(SessionFactory sessionFactory)
    {
        this.sessionFactory = sessionFactory;
    }
    
    @Override
    @Transactional
    public void delete(T vo)
    {
        try
        {
            this.sessionFactory.getCurrentSession().delete(vo);
        }
        catch (final HibernateException ex)
        {
            HibernateDaoGenerico.LOG.error(ex);
        }
    }

    @Override
    @SuppressWarnings("unchecked")
    public T findById(ID id)
    {
        return (T) this.sessionFactory.getCurrentSession().get(getPersistentClass(), id);
    }
    
    @Override
    public List<T> listAll()
    {
        return this.sessionFactory.getCurrentSession().createCriteria(this.getPersistentClass()).list();
    }
    
    @Override
    @Transactional
    public T save(T vo)
    {
        this.sessionFactory.getCurrentSession().save(vo);

        return vo;
    }
    
    protected List<T> findByCriteria(Criterion... criterion)
    {
        Criteria criteria = this.sessionFactory.getCurrentSession().createCriteria(this.getPersistentClass());

        for (Criterion c : criterion)
        {
            criteria.add(c);
        }

        return criteria.list();
    }    
}
17/06/2011 17:26:14 org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
17/06/2011 17:26:15 org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
17/06/2011 17:26:22 org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
17/06/2011 17:26:23 org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
17/06/2011 17:26:25 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet default threw exception
br.com.caelum.vraptor.InterceptionException: java.lang.NullPointerException
	at br.com.caelum.vraptor.interceptor.ExecuteMethodInterceptor.intercept(ExecuteMethodInterceptor.java:72)
	at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:45)
	at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:59)
	at br.com.caelum.vraptor.interceptor.ParametersInstantiatorInterceptor.intercept(ParametersInstantiatorInterceptor.java:83)
	at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:45)
	at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:59)
	at br.com.caelum.vraptor.interceptor.InstantiateInterceptor.intercept(InstantiateInterceptor.java:42)
	at br.com.caelum.vraptor.core.InstantiatedInterceptorHandler.execute(InstantiatedInterceptorHandler.java:39)
	at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:59)
	at br.com.caelum.vraptor.interceptor.multipart.MultipartInterceptor.intercept(MultipartInterceptor.java:74)
	at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:45)
	at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:59)
	at br.com.caelum.vraptor.interceptor.InterceptorListPriorToExecutionExtractor.intercept(InterceptorListPriorToExecutionExtractor.java:46)
	at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:45)
	at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:59)
	at br.com.caelum.vraptor.core.URLParameterExtractorInterceptor.intercept(URLParameterExtractorInterceptor.java:35)
	at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:45)
	at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:59)
	at br.com.caelum.vraptor.interceptor.ResourceLookupInterceptor.intercept(ResourceLookupInterceptor.java:58)
	at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:45)
	at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:59)
	at br.com.caelum.vraptor.core.DefaultRequestExecution.execute(DefaultRequestExecution.java:59)
	at br.com.caelum.vraptor.VRaptor$1.insideRequest(VRaptor.java:87)
	at br.com.caelum.vraptor.ioc.spring.SpringProvider.provideForRequest(SpringProvider.java:55)
	at br.com.caelum.vraptor.VRaptor.doFilter(VRaptor.java:85)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.NullPointerException
	at br.com.vraptor.dao.hibernate.HibernateDaoGenerico.findByCriteria(HibernateDaoGenerico.java:92)
	at br.com.vraptor.dao.hibernate.PessoaHibernateDao.findPessoasWithChapa(PessoaHibernateDao.java:45)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
	at $Proxy179.findPessoasWithChapa(Unknown Source)
	at br.com.vraptor.controller.IndexController.index(IndexController.java:39)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at br.com.caelum.vraptor.interceptor.ExecuteMethodInterceptor.intercept(ExecuteMethodInterceptor.java:50)
	... 36 more

Olha... Desde já agradeço a enorme atenção da sua parte.

[]'s

Lucas_Cavalcanti

se você usa o hibernateDaoGenerico diretamente, você precisa anotá-lo com @Component, e receber a session no construtor.

se você só usa as filhas, vc precisa anotar as filhas com @Component e receber a sessionFactory no construtor, e passar no construtor do genérico.

e sim, a sessionFactory passada é a que foi configurada pelo Spring, o VRaptor se integra totalmente com ele

R

Lucas Cavalcanti:
se você usa o hibernateDaoGenerico diretamente, você precisa anotá-lo com @Component, e receber a session no construtor.

se você só usa as filhas, vc precisa anotar as filhas com @Component e receber a sessionFactory no construtor, e passar no construtor do genérico.

e sim, a sessionFactory passada é a que foi configurada pelo Spring, o VRaptor se integra totalmente com ele

Lucas,

Coloquei o @Component nas classes filhas. Só que agora o o problema é o seguinte:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [br.com.vraptor.dao.hibernate.IPessoaDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {} at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:896) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:765) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:680) at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:771) at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:691) ... 46 more

Quando estava da outra forma ele chegava a passar o sessionFactory instanciado, só que na hora de criteriar ele dava um NullPointer.

Acho que estou deixando algo passar batido.

[]'s
Daniel Razah.

Lucas_Cavalcanti

existe alguma classe anotada com @Component que implements IPessoaDao?

R

Lucas,

Sim… Existe a PessoaHibernateDao.

[]'s,
Daniel Razah.

Lucas_Cavalcanti

deveria funcionar então… @Component do VRaptor, certo?

tem alguma coisa a mais nos caused-by da exception?

R

Lucas Cavalcanti:
deveria funcionar então… @Component do VRaptor, certo?

tem alguma coisa a mais nos caused-by da exception?

Lucas,

Ele completo:

20/06/2011 15:57:55 org.apache.catalina.core.StandardWrapperValve invoke GRAVE: Servlet.service() for servlet default threw exception org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'indexController' defined in file [/Users/daniel.rfonseca/Desktop/Arquivos/Aplicacoes/JAVA/Senac/VRaptor/build/web/WEB-INF/classes/br/com/vraptor/controller/IndexController.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [br.com.vraptor.dao.hibernate.IPessoaDao]: : No matching bean of type [br.com.vraptor.dao.hibernate.IPessoaDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [br.com.vraptor.dao.hibernate.IPessoaDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {} at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:698) at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:192) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:984) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:886) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:479) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450) at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:328) at org.springframework.web.context.request.AbstractRequestAttributesScope.get(AbstractRequestAttributesScope.java:43) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:385) at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:375) at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1069) at org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(BeanFactoryUtils.java:221) at br.com.caelum.vraptor.ioc.spring.VRaptorApplicationContext.getBean(VRaptorApplicationContext.java:203) at br.com.caelum.vraptor.ioc.spring.SpringBasedContainer.instanceFor(SpringBasedContainer.java:61) at br.com.caelum.vraptor.interceptor.InstantiateInterceptor.intercept(InstantiateInterceptor.java:41) at br.com.caelum.vraptor.core.InstantiatedInterceptorHandler.execute(InstantiatedInterceptorHandler.java:39) at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:59) at br.com.caelum.vraptor.interceptor.multipart.MultipartInterceptor.intercept(MultipartInterceptor.java:74) at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:45) at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:59) at br.com.caelum.vraptor.interceptor.InterceptorListPriorToExecutionExtractor.intercept(InterceptorListPriorToExecutionExtractor.java:46) at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:45) at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:59) at br.com.caelum.vraptor.core.URLParameterExtractorInterceptor.intercept(URLParameterExtractorInterceptor.java:35) at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:45) at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:59) at br.com.caelum.vraptor.interceptor.ResourceLookupInterceptor.intercept(ResourceLookupInterceptor.java:58) at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:45) at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:59) at br.com.caelum.vraptor.core.DefaultRequestExecution.execute(DefaultRequestExecution.java:59) at br.com.caelum.vraptor.VRaptor$1.insideRequest(VRaptor.java:87) at br.com.caelum.vraptor.ioc.spring.SpringProvider.provideForRequest(SpringProvider.java:55) at br.com.caelum.vraptor.VRaptor.doFilter(VRaptor.java:85) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:680) Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [br.com.vraptor.dao.hibernate.IPessoaDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {} at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:896) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:765) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:680) at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:771) at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:691) ... 46 more

[]'s
Daniel Razah.

Lucas_Cavalcanti

os seus daos estão dentro de jars?

se sim, vc precisa acrescentar na configuração packages:

<context-param>  
        <!-- Nao mexer configuracao do vraptor -->  
        <param-name>br.com.caelum.vraptor.packages</param-name>  
          
        <!-- Meus controllers -->  
        <param-value>br.com.vraptor.controller, br.com.vraptor.dao.hibernate</param-value>  
    </context-param>
R
Lucas Cavalcanti:
os seus daos estão dentro de jars? se sim, vc precisa acrescentar na configuração packages:
<context-param>  
        <!-- Nao mexer configuracao do vraptor -->  
        <param-name>br.com.caelum.vraptor.packages</param-name>  
          
        <!-- Meus controllers -->  
        <param-value>br.com.vraptor.controller, br.com.vraptor.dao.hibernate</param-value>  
    </context-param>

Lucas,

Estão dentro do próprio projeto.

[]'s

Lucas_Cavalcanti

o dao tá anotado com @Component do VRaptor?

R

Opa… Fala ai Lucas blz?

Estive fora ontem e por esse motivo não respondi a mensagem!

Cara a classe PessoaHibernateDao esta anotado com @Component do VRaptor.

[]'s

Lucas_Cavalcanti

habilita o log de debug do VRaptor e posta aqui o que aparece na inicialização do servidor, por favor?

R

Lucas,

Segue:

22/06/2011 12:08:17 org.apache.catalina.core.AprLifecycleListener init INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java 22/06/2011 12:08:18 org.apache.coyote.http11.Http11Protocol init INFO: Initializing Coyote HTTP/1.1 on http-8084 22/06/2011 12:08:18 org.apache.catalina.startup.Catalina load INFO: Initialization processed in 578 ms 22/06/2011 12:08:18 org.apache.catalina.core.StandardService start INFO: Starting service Catalina 22/06/2011 12:08:18 org.apache.catalina.core.StandardEngine start INFO: Starting Servlet Engine: Apache Tomcat/6.0.26 22/06/2011 12:08:18 org.apache.catalina.startup.HostConfig deployDescriptor INFO: Deploying configuration descriptor host-manager.xml 22/06/2011 12:08:18 org.apache.catalina.startup.HostConfig deployDescriptor INFO: Deploying configuration descriptor manager.xml 22/06/2011 12:08:18 org.apache.catalina.startup.HostConfig deployDescriptor INFO: Deploying configuration descriptor Recru.xml 22/06/2011 12:08:18 org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory docs 22/06/2011 12:08:18 org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory examples 22/06/2011 12:08:19 org.apache.coyote.http11.Http11Protocol start INFO: Starting Coyote HTTP/1.1 on http-8084 22/06/2011 12:08:19 org.apache.jk.common.ChannelSocket init INFO: JK: ajp13 listening on /0.0.0.0:8009 22/06/2011 12:08:19 org.apache.jk.server.JkMain start INFO: Jk running ID=0 time=0/31 config=null 22/06/2011 12:08:19 org.apache.catalina.startup.Catalina start INFO: Server startup in 1226 ms 22/06/2011 12:08:19 org.apache.catalina.startup.HostConfig deployDescriptor INFO: Deploying configuration descriptor VRaptor.xml log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader). log4j:WARN Please initialize the log4j system properly. 12:08:21,668 INFO [VRaptorApplicationContext] Refreshing Root WebApplicationContext: startup date [Wed Jun 22 12:08:21 BRT 2011]; parent: Root WebApplicationContext 12:08:21,765 DEBUG [ComponentScanner ] Identified candidate component class: file [/Users/daniel.rfonseca/Desktop/Arquivos/Aplicacoes/JAVA/Senac/VRaptor/build/web/WEB-INF/classes/br/com/vraptor/controller/IndexController.class] 12:08:21,770 DEBUG [VRaptorApplicationContext] Bean factory for Root WebApplicationContext: org.springframework.beans.factory.support.DefaultListableBeanFactory@24b6a561: defining beans [defaultMultipartConfig,emptyElementsRemoval,defaultTypeFinder,asmBasedTypeCreator,defaultResourceTranslator,pathAnnotationRoutesParser,defaultAcceptHeaderToFormat,defaultResourceNotFoundHandler,paranamerNameProvider,defaultRouter,defaultConverters,defaultInterceptorRegistry,objenesisProxifier,noRoutesConfiguration,stereotypeHandler,converterHandler,interceptorStereotypeHandler,stereotypedBeansRegistrar,defaultSpringLocator,defaultValidationViewsFactory,emptyResult,executeMethodInterceptor,forwardToDefaultViewInterceptor,URLParameterExtractorInterceptor,defaultMethodInfo,resourceLookupInterceptor,defaultLogicResult,defaultHttpResult,interceptorListPriorToExecutionExtractor,parametersInstantiatorInterceptor,ognlParametersProvider,downloadInterceptor,multipartInterceptor,defaultValidator,defaultInterceptorStack,instantiateInterceptor,defaultPathResolver,defaultResult,jstlLocalization,defaultPageResult,outjectResult,defaultRequestExecution,bigDecimalConverter,bigIntegerConverter,booleanConverter,byteConverter,characterConverter,doubleConverter,enumConverter,floatConverter,integerConverter,localeBasedCalendarConverter,localeBasedDateConverter,longConverter,primitiveBooleanConverter,primitiveByteConverter,primitiveCharConverter,primitiveDoubleConverter,primitiveFloatConverter,primitiveIntConverter,primitiveLongConverter,primitiveShortConverter,shortConverter,uploadedFileConverter,VRaptorRequestProvider,httpServletRequestProvider,httpServletResponseProvider,httpSessionProvider,indexController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.aop.config.internalAutoProxyCreator,cacheBasedTypeCreator]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@3b8e80a6 12:08:21,848 DEBUG [VRaptorApplicationContext] Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@37d6d61d] 12:08:21,848 DEBUG [VRaptorApplicationContext] Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@7983268e] 12:08:21,858 DEBUG [VRaptorApplicationContext] Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycleProcessor@45e33bb8] 12:08:21,958 INFO [DefaultConverters ] Registering bundled converters 12:08:21,958 DEBUG [DefaultConverters ] bundled converter to be registered: class br.com.caelum.vraptor.converter.BigDecimalConverter 12:08:21,958 DEBUG [DefaultConverters ] bundled converter to be registered: class br.com.caelum.vraptor.converter.BigIntegerConverter 12:08:21,958 DEBUG [DefaultConverters ] bundled converter to be registered: class br.com.caelum.vraptor.converter.BooleanConverter 12:08:21,958 DEBUG [DefaultConverters ] bundled converter to be registered: class br.com.caelum.vraptor.converter.ByteConverter 12:08:21,958 DEBUG [DefaultConverters ] bundled converter to be registered: class br.com.caelum.vraptor.converter.CharacterConverter 12:08:21,958 DEBUG [DefaultConverters ] bundled converter to be registered: class br.com.caelum.vraptor.converter.DoubleConverter 12:08:21,958 DEBUG [DefaultConverters ] bundled converter to be registered: class br.com.caelum.vraptor.converter.EnumConverter 12:08:21,958 DEBUG [DefaultConverters ] bundled converter to be registered: class br.com.caelum.vraptor.converter.FloatConverter 12:08:21,958 DEBUG [DefaultConverters ] bundled converter to be registered: class br.com.caelum.vraptor.converter.IntegerConverter 12:08:21,958 DEBUG [DefaultConverters ] bundled converter to be registered: class br.com.caelum.vraptor.converter.LocaleBasedCalendarConverter 12:08:21,958 DEBUG [DefaultConverters ] bundled converter to be registered: class br.com.caelum.vraptor.converter.LocaleBasedDateConverter 12:08:21,958 DEBUG [DefaultConverters ] bundled converter to be registered: class br.com.caelum.vraptor.converter.LongConverter 12:08:21,959 DEBUG [DefaultConverters ] bundled converter to be registered: class br.com.caelum.vraptor.converter.PrimitiveBooleanConverter 12:08:21,959 DEBUG [DefaultConverters ] bundled converter to be registered: class br.com.caelum.vraptor.converter.PrimitiveByteConverter 12:08:21,959 DEBUG [DefaultConverters ] bundled converter to be registered: class br.com.caelum.vraptor.converter.PrimitiveCharConverter 12:08:21,959 DEBUG [DefaultConverters ] bundled converter to be registered: class br.com.caelum.vraptor.converter.PrimitiveDoubleConverter 12:08:21,959 DEBUG [DefaultConverters ] bundled converter to be registered: class br.com.caelum.vraptor.converter.PrimitiveFloatConverter 12:08:21,959 DEBUG [DefaultConverters ] bundled converter to be registered: class br.com.caelum.vraptor.converter.PrimitiveIntConverter 12:08:21,959 DEBUG [DefaultConverters ] bundled converter to be registered: class br.com.caelum.vraptor.converter.PrimitiveLongConverter 12:08:21,959 DEBUG [DefaultConverters ] bundled converter to be registered: class br.com.caelum.vraptor.converter.PrimitiveShortConverter 12:08:21,959 DEBUG [DefaultConverters ] bundled converter to be registered: class br.com.caelum.vraptor.converter.ShortConverter 12:08:21,959 DEBUG [DefaultConverters ] bundled converter to be registered: class br.com.caelum.vraptor.interceptor.multipart.UploadedFileConverter 12:08:21,982 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.interceptor.multipart.DefaultMultipartConfig, to see if it is a component candidate 12:08:21,983 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.http.ognl.EmptyElementsRemoval, to see if it is a component candidate 12:08:21,983 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.http.route.DefaultTypeFinder, to see if it is a component candidate 12:08:21,984 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.http.asm.AsmBasedTypeCreator, to see if it is a component candidate 12:08:21,984 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.http.DefaultResourceTranslator, to see if it is a component candidate 12:08:21,984 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.http.route.PathAnnotationRoutesParser, to see if it is a component candidate 12:08:21,984 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.view.DefaultAcceptHeaderToFormat, to see if it is a component candidate 12:08:21,984 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.resource.DefaultResourceNotFoundHandler, to see if it is a component candidate 12:08:21,984 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.http.ParanamerNameProvider, to see if it is a component candidate 12:08:21,984 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.http.route.DefaultRouter, to see if it is a component candidate 12:08:21,984 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.core.DefaultConverters, to see if it is a component candidate 12:08:21,984 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.interceptor.DefaultInterceptorRegistry, to see if it is a component candidate 12:08:21,984 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.proxy.ObjenesisProxifier, to see if it is a component candidate 12:08:21,984 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.http.route.NoRoutesConfiguration, to see if it is a component candidate 12:08:21,985 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.ioc.ResourceHandler, to see if it is a component candidate 12:08:21,985 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.ioc.ConverterHandler, to see if it is a component candidate 12:08:21,985 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.ioc.InterceptorStereotypeHandler, to see if it is a component candidate 12:08:21,985 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.ioc.spring.StereotypedBeansRegistrar, to see if it is a component candidate 12:08:21,985 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.ioc.spring.DefaultSpringLocator, to see if it is a component candidate 12:08:21,985 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.view.DefaultValidationViewsFactory, to see if it is a component candidate 12:08:21,985 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.view.EmptyResult, to see if it is a component candidate 12:08:21,985 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.interceptor.ExecuteMethodInterceptor, to see if it is a component candidate 12:08:21,985 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.extra.ForwardToDefaultViewInterceptor, to see if it is a component candidate 12:08:21,985 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.core.URLParameterExtractorInterceptor, to see if it is a component candidate 12:08:21,986 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.core.DefaultMethodInfo, to see if it is a component candidate 12:08:21,986 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.interceptor.ResourceLookupInterceptor, to see if it is a component candidate 12:08:21,986 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.view.DefaultLogicResult, to see if it is a component candidate 12:08:21,986 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.view.DefaultHttpResult, to see if it is a component candidate 12:08:21,986 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.interceptor.InterceptorListPriorToExecutionExtractor, to see if it is a component candidate 12:08:21,986 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.interceptor.ParametersInstantiatorInterceptor, to see if it is a component candidate 12:08:21,986 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.http.ognl.OgnlParametersProvider, to see if it is a component candidate 12:08:21,986 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.interceptor.download.DownloadInterceptor, to see if it is a component candidate 12:08:21,986 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.interceptor.multipart.MultipartInterceptor, to see if it is a component candidate 12:08:21,986 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.validator.DefaultValidator, to see if it is a component candidate 12:08:21,987 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.core.DefaultInterceptorStack, to see if it is a component candidate 12:08:21,987 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.interceptor.InstantiateInterceptor, to see if it is a component candidate 12:08:21,987 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.view.DefaultPathResolver, to see if it is a component candidate 12:08:21,987 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.core.DefaultResult, to see if it is a component candidate 12:08:21,987 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.core.JstlLocalization, to see if it is a component candidate 12:08:21,987 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.view.DefaultPageResult, to see if it is a component candidate 12:08:21,987 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.interceptor.OutjectResult, to see if it is a component candidate 12:08:21,987 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.core.DefaultRequestExecution, to see if it is a component candidate 12:08:21,987 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.converter.BigDecimalConverter, to see if it is a component candidate 12:08:21,987 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.converter.BigIntegerConverter, to see if it is a component candidate 12:08:21,988 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.converter.BooleanConverter, to see if it is a component candidate 12:08:21,988 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.converter.ByteConverter, to see if it is a component candidate 12:08:21,988 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.converter.CharacterConverter, to see if it is a component candidate 12:08:21,988 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.converter.DoubleConverter, to see if it is a component candidate 12:08:21,988 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.converter.EnumConverter, to see if it is a component candidate 12:08:21,988 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.converter.FloatConverter, to see if it is a component candidate 12:08:21,988 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.converter.IntegerConverter, to see if it is a component candidate 12:08:21,988 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.converter.LocaleBasedCalendarConverter, to see if it is a component candidate 12:08:21,988 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.converter.LocaleBasedDateConverter, to see if it is a component candidate 12:08:21,989 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.converter.LongConverter, to see if it is a component candidate 12:08:21,989 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.converter.PrimitiveBooleanConverter, to see if it is a component candidate 12:08:21,989 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.converter.PrimitiveByteConverter, to see if it is a component candidate 12:08:21,989 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.converter.PrimitiveCharConverter, to see if it is a component candidate 12:08:21,989 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.converter.PrimitiveDoubleConverter, to see if it is a component candidate 12:08:21,989 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.converter.PrimitiveFloatConverter, to see if it is a component candidate 12:08:21,989 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.converter.PrimitiveIntConverter, to see if it is a component candidate 12:08:21,989 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.converter.PrimitiveLongConverter, to see if it is a component candidate 12:08:21,989 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.converter.PrimitiveShortConverter, to see if it is a component candidate 12:08:21,990 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.converter.ShortConverter, to see if it is a component candidate 12:08:21,990 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.interceptor.multipart.UploadedFileConverter, to see if it is a component candidate 12:08:21,990 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.core.RequestInfo, to see if it is a component candidate 12:08:21,990 DEBUG [StereotypedBeansRegistrar] scanning bean with type: interface br.com.caelum.vraptor.http.MutableRequest, to see if it is a component candidate 12:08:21,990 DEBUG [StereotypedBeansRegistrar] scanning bean with type: interface javax.servlet.http.HttpServletResponse, to see if it is a component candidate 12:08:21,990 DEBUG [StereotypedBeansRegistrar] scanning bean with type: interface javax.servlet.http.HttpSession, to see if it is a component candidate 12:08:21,990 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.vraptor.controller.IndexController, to see if it is a component candidate 12:08:21,990 DEBUG [ResourceRegistrar ] Found resource: class br.com.vraptor.controller.IndexController 12:08:22,002 DEBUG [DefaultParametersControl] For /index.html retrieved /index.html with {} 12:08:22,003 INFO [RouteBuilder ] /index.html --> public java.util.List br.com.vraptor.controller.IndexController.index() 12:08:22,004 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class org.springframework.context.annotation.ConfigurationClassPostProcessor, to see if it is a component candidate 12:08:22,004 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.ioc.spring.InjectionBeanPostProcessor, to see if it is a component candidate 12:08:22,004 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor, to see if it is a component candidate 12:08:22,009 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class org.springframework.context.annotation.CommonAnnotationBeanPostProcessor, to see if it is a component candidate 12:08:22,009 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor, to see if it is a component candidate 12:08:22,010 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator, to see if it is a component candidate 12:08:22,010 DEBUG [StereotypedBeansRegistrar] scanning bean with type: class br.com.caelum.vraptor.reflection.CacheBasedTypeCreator, to see if it is a component candidate 12:08:22,060 INFO [VRaptor ] VRaptor 3 successfuly initialized 22/06/2011 12:08:22 org.apache.catalina.core.StandardContext start INFO: Container org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/VRaptor] has already been started 12:08:22,721 DEBUG [DefaultResourceTranslator] trying to access / 12:08:22,730 DEBUG [DefaultResourceTranslator] found resource null

[]'s
Daniel Razah.

Lucas_Cavalcanti

Você está com uma versão bem antiga do vraptor… tenta atualizar pra última, por favor…

baixe o zip do blank project http://code.google.com/p/vraptor3/downloads/detail?name=vraptor-blank-project-3.3.1.zip&can=2&q=
e copie todos os jars de WEB-INF/lib para sua aplicação…

se você está usando spring 2.5 você precisa atualizar para 3.0.x (já está no blank)

dê uma olhada nas libs que ficaram repetidas (provavelmente o paranamer, log4j, slf4j) e remova a mais antiga.
remova também a google-collect (agora ela se chama guava)

[]'s

R

Lucas,

Fiz testes com openSession e funcionou, já quando utilizo getCurrentSession ele da o erro abaixo:

27/06/2011 12:03:44 org.apache.catalina.core.ApplicationContext log INFO: Initializing Spring root WebApplicationContext 27/06/2011 12:03:57 org.apache.catalina.core.StandardWrapperValve invoke GRAVE: Servlet.service() for servlet default threw exception br.com.caelum.vraptor.InterceptionException: exception raised, check root cause for details: org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here at br.com.caelum.vraptor.interceptor.ExecuteMethodInterceptor.intercept(ExecuteMethodInterceptor.java:96) at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54) at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54) at br.com.caelum.vraptor.core.LazyInterceptorHandler.execute(LazyInterceptorHandler.java:61) at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54) at br.com.caelum.vraptor.interceptor.FlashInterceptor.intercept(FlashInterceptor.java:83) at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54) at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54) at br.com.caelum.vraptor.interceptor.ExceptionHandlerInterceptor.intercept(ExceptionHandlerInterceptor.java:71) at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54) at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54) at br.com.caelum.vraptor.interceptor.InstantiateInterceptor.intercept(InstantiateInterceptor.java:48) at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54) at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54) at br.com.caelum.vraptor.core.LazyInterceptorHandler.execute(LazyInterceptorHandler.java:61) at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54) at br.com.caelum.vraptor.interceptor.ResourceLookupInterceptor.intercept(ResourceLookupInterceptor.java:69) at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54) at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54) at br.com.caelum.vraptor.core.EnhancedRequestExecution.execute(EnhancedRequestExecution.java:23) at br.com.caelum.vraptor.VRaptor$1.insideRequest(VRaptor.java:92) at br.com.caelum.vraptor.ioc.spring.SpringProvider.provideForRequest(SpringProvider.java:58) at br.com.caelum.vraptor.VRaptor.doFilter(VRaptor.java:89) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:680) Caused by: org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here at org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63) at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:544) at br.com.vraptor.dao.hibernate.HibernateDaoGenerico.findByCriteria(HibernateDaoGenerico.java:90) at br.com.vraptor.dao.hibernate.PessoaHibernateDao.findPessoasWithChapa(PessoaHibernateDao.java:41) at br.com.vraptor.controller.IndexController.index(IndexController.java:40) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at br.com.caelum.vraptor.interceptor.ExecuteMethodInterceptor.intercept(ExecuteMethodInterceptor.java:61) ... 34 more

Não sei… Tenho a impressão que o spring não esta gerenciando as transações!

[]'s

Lucas_Cavalcanti

você chegou a configurar a sessionFactory e o tx: no applicationContext?

R

Sim,

Segue ai:

<?xml version="1.0" encoding="ISO-8859-1"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
       xmlns:context="http://www.springframework.org/schema/context" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xmlns:cxf="http://cxf.apache.org/core" 
       xmlns:jaxrs="http://cxf.apache.org/jaxrs" 
       xmlns:jaxws="http://cxf.apache.org/jaxws" 
       xmlns:tx="http://www.springframework.org/schema/tx" 
       xmlns:p="http://www.springframework.org/schema/aop" 
       xsi:schemaLocation=" 
       http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
       http://www.springframework.org/schema/context  
       http://www.springframework.org/schema/context/spring-context-3.0.xsd 
       http://www.springframework.org/schema/tx 
       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
       http://www.springframework.org/schema/aop 
       http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> 
           
           <!-- ****** Inicio dos arquivos de configuracao ****** -->
           <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
              <property name="locations">
                 <list>  
                    <value>/WEB-INF/jdbc.properties</value>
                 </list>  
              </property>  
           </bean>
           
           <!-- Bean com as configuracoes de conexao com o banco, utilizado CommonsDBCP da Apache para gerenciar nosso pool de conexão -->
           <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
               <property name="driverClassName" value="${database.driver}" />  
               <property name="url"             value="${database.url}" />  
               <property name="username"        value="${database.user}" />  
               <property name="password"        value="${database.pass}" />  
               <property name="initialSize"     value="${database.initConnections}" />  
               <property name="maxActive"       value="${database.maxActive}" />
               <property name="maxIdle"         value="${database.maxIdle}" />
               <property name="removeAbandoned" value="${database.removeAbandoned}" />
           </bean>                      
           
           <!-- Fabrica de sessoes -->
           <bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
               <property name="dataSource">  
                   <ref local="dataSource" />  
               </property>
               
               <property name="annotatedClasses">  
                   <list>  
                       <value>br.com.vraptor.vo.PessoaVo</value>
                   </list>
               </property>
               
               <property name="hibernateProperties">
                   <props>
                       <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
                       <prop key="hibernate.show_sql">true</prop>
                       <prop key="hibernate.format_sql">true</prop>
                   </props>  
               </property>  
           </bean>
                                 
           <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
                <property name="sessionFactory" ref="hibernateSessionFactory" />
           </bean>
           
           <tx:annotation-driven transaction-manager="transactionManager" />
           
           <!-- Faz a indentificacao dos beans anotados com @Service, @Repository e @Controller -->
           <context:component-scan base-package="br.com.vraptor.controller" />
           <context:component-scan base-package="br.com.vraptor.dao.hibernate" />
           
           <!-- Habilita a configuracao de beans via anotacoes -->
           <context:annotation-config />
</beans>
Lucas_Cavalcanti

Lá no HibernateDaoGenerico vc não pode fazer sessionFactory.getCurrentSession()

vc precisa usar o spring pra isso…

um dos jeitos é com:

Session sesion = SessionFactoryUtils.getSession(sessionFactory); // ou algo parecido

outro é recebendo HibernateTemplate como dependência e usando ele para fazer tudo

ou ainda usando o SessionCreator que está no apêndice de Spring transactional da apostila do VRAptor
http://www.caelum.com.br/curso/fj-28-vraptor-hibernate-ajax/

R

Lucas,

Consegui resolver!

No contrutor do dao generico eu adicionai por session:

Achei que o spring injetaria a dependência sessionFactory e daria para usar getCurrentSession(), mas acho que estava enganado!

Agradeço muito sua ajuda!!!

[]'s
Daniel Razah.
Bem dito é o que vem em nome de HASHEM O ETERNO.

Criado 17 de junho de 2011
Ultima resposta 28 de jun. de 2011
Respostas 25
Participantes 2