GUJ Discussões   :   últimos tópicos   |   categorias   |   GUJ Respostas

[Resolvido] VRaptor 3.1 + JEE6 + Hibernate


#1

Como configuro o Provider do hibernate no JEE6??

o VRaptor não consegue injetar o session, pq ele não achou oq injetar, e nem existe mesmo

Sem o web.xml não sei onde coloca as definição

Em outro teste que eu havia feito, estava dando erro pq ele não achava o arquivo de configuração do Hibernate, mesmo eu não configurando nada, agora ele nem erro dá

Tentei colocar um web-fragment na pasta WEB-INF com os dados e não foi

[Edit:]

Eu tenho que usar as anotações e definir os Providers na mão??

Ou posso utilizar o pronto?? e como??


#2

vc precisa setar o context-param do HibernateCustomProvider... basta colocar isso no web.xml... Não sei se vc pode colocar isso em algum outro lugar, mas o web.xml ainda funciona...

<context-param>
    <param-name>br.com.caelum.vraptor.provider</param-name>
    <param-value>br.com.caelum.vraptor.util.hibernate.HibernateCustomProvider</param-value>
</context-param>

#3

Mas sem XML, não é possível?

Pois no padrão JEE 6, eu nem tenho um web.xml, eu teria que criar um


#4

acho que vc pode criar uma classe do tipo:

@ServletContextListener
public class MyListener {
    public void contextInitialized(ServletContext context) {
            context.setParameter("br.com.caelum.vraptor.provider", HibernateCustomProvider.class.getName());
    }
}

via fragments não vi como


#5

Valeu Lucas, fiz mais ou menos do jeito que vc disse

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.exemplo.config;
import br.com.caelum.vraptor.util.hibernate.HibernateCustomProvider;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
/**
 *
 * @author Felipe
 */
@javax.servlet.annotation.WebListener
public class MyListener implements ServletContextListener {
    public void contextInitialized(ServletContextEvent sce) {
        sce.getServletContext().setInitParameter("br.com.caelum.vraptor.provider", HibernateCustomProvider.class.getName());
    }
    public void contextDestroyed(ServletContextEvent sce) {
    }
}

#6

Dando uma resucitada neste post!.. hehe

Estou tentando fazer a configuração de VRaptor 3.2 + JE66 + Hibernate... mas nao estou conseguindo inicializar EntityManager..
eu tentei fazer esta abordagem apresentada, mas estou tomando o seguinte erro logo na hra q tento subir o jetty

2011-11-21 09:37:28.960:WARN::FAILED vraptor: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactoryCreator': Invocation of init method failed; nested exception is org.hibernate.HibernateException: /hibernate.cfg.xml not found
2011-11-21 09:37:28.960:WARN::Failed startup of context o.m.j.p.JettyWebAppContext{/protocol,file:/Users/kbernardo/Documents/workspaces/hanoi/hanoi-fluxo-online/servicos/protocol-service/src/main/webapp/},file:/Users/kbernardo/Documents/workspaces/hanoi/hanoi-fluxo-online/servicos/protocol-service/src/main/webapp/
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactoryCreator': Invocation of init method failed; nested exception is org.hibernate.HibernateException: /hibernate.cfg.xml not found
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:133)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:394)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1413)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
	at br.com.caelum.vraptor.ioc.spring.SpringBasedContainer.start(SpringBasedContainer.java:106)
	at br.com.caelum.vraptor.ioc.spring.SpringProvider.start(SpringProvider.java:87)
	at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:110)
	at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:103)
	at org.eclipse.jetty.servlet.FilterHolder.doStart(FilterHolder.java:111)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
	at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:750)
	at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:251)
	at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1208)
	at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:608)
	at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:449)
	at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:231)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
	at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:224)
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:164)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
	at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:224)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
	at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:89)
	at org.eclipse.jetty.server.Server.doStart(Server.java:259)
	at org.mortbay.jetty.plugin.JettyServer.doStart(JettyServer.java:67)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
	at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:333)
	at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:273)
	at org.mortbay.jetty.plugin.JettyRunMojo.execute(JettyRunMojo.java:548)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:534)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
	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.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: 
org.hibernate.HibernateException: /hibernate.cfg.xml not found
	at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:170)
	at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1497)
	at org.hibernate.cfg.Configuration.configure(Configuration.java:1519)
	at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:1194)
	at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:107)
	at org.hibernate.cfg.Configuration.configure(Configuration.java:1506)
	at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:1188)
	at br.com.caelum.vraptor.util.hibernate.SessionFactoryCreator.create(SessionFactoryCreator.java:43)
	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.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:340)
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:293)
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:130)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:394)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1413)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
	at br.com.caelum.vraptor.ioc.spring.SpringBasedContainer.start(SpringBasedContainer.java:106)
	at br.com.caelum.vraptor.ioc.spring.SpringProvider.start(SpringProvider.java:87)
	at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:110)
	at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:103)
	at org.eclipse.jetty.servlet.FilterHolder.doStart(FilterHolder.java:111)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
	at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:750)
	at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:251)
	at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1208)
	at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:608)
	at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:449)
	at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:231)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
	at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:224)
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:164)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
	at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:224)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
	at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:89)
	at org.eclipse.jetty.server.Server.doStart(Server.java:259)
	at org.mortbay.jetty.plugin.JettyServer.doStart(JettyServer.java:67)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
	at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:333)
	at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:273)
	at org.mortbay.jetty.plugin.JettyRunMojo.execute(JettyRunMojo.java:548)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:534)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
	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.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
2011-11-21 09:37:28.996:INFO::Started SelectChannelConnector@0.0.0.0:4000 STARTING

Pelo que eu sei, nao preciso definir este cara 'hibernate.cfg.xml' uma vez q estou fazendo com anotetaions e tudo mais.
o meu web.xml está assim

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
	version="3.0">
	<session-config>
		<session-timeout>30</session-timeout>
	</session-config>
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
</web-app>

e o applicationContext.xml nao tem nenhuma configuração

<?xml version="1.0" encoding="UTF-8"?>
<beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd  
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">  
</beans>

alguma dica?

obrigado


#7

apenas tirando o removido do nome


#8

Você precisa do arquivo do hibernate para dizer quais são os dados de acesso ao banco e quem são as entidades


#9

e quando eu deixo sem o listener e com a configuração no web.xml ele da o seguinte erro

2011-11-21 10:13:49.375:WARN::FAILED vraptor: java.security.AccessControlException: access denied (java.lang.RuntimePermission getClassLoader)
2011-11-21 10:13:49.376:WARN::Failed startup of context o.m.j.p.JettyWebAppContext{/protocol,file:/Users/kbernardo/Documents/workspaces/hanoi/hanoi-fluxo-online/servicos/protocol-service/src/main/webapp/},file:/Users/kbernardo/Documents/workspaces/hanoi/hanoi-fluxo-online/servicos/protocol-service/src/main/webapp/
java.security.AccessControlException: access denied (java.lang.RuntimePermission getClassLoader)
	at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
	at java.security.AccessController.checkPermission(AccessController.java:546)
	at org.eclipse.jetty.server.handler.ContextHandler$Context.getClassLoader(ContextHandler.java:2177)
	at br.com.caelum.vraptor.scan.WebBasedClasspathResolver.getClassLoader(WebBasedClasspathResolver.java:43)
	at br.com.caelum.vraptor.scan.ScannotationComponentScanner.scanPackage(ScannotationComponentScanner.java:96)
	at br.com.caelum.vraptor.scan.ScannotationComponentScanner.scanBasePackages(ScannotationComponentScanner.java:83)
	at br.com.caelum.vraptor.scan.ScannotationComponentScanner.scan(ScannotationComponentScanner.java:58)
	at br.com.caelum.vraptor.scan.WebAppBootstrapFactory.create(WebAppBootstrapFactory.java:65)
	at br.com.caelum.vraptor.ioc.spring.SpringProvider.start(SpringProvider.java:83)
	at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:110)
	at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:103)
	at org.eclipse.jetty.servlet.FilterHolder.doStart(FilterHolder.java:111)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
	at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:750)
	at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:251)
	at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1208)
	at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:608)
	at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:449)
	at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:231)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
	at org.mortbay.jetty.plugin.JettyRunMojo.restartWebApp(JettyRunMojo.java:440)
	at org.mortbay.jetty.plugin.JettyRunMojo$1.filesChanged(JettyRunMojo.java:403)
	at org.eclipse.jetty.util.Scanner.reportBulkChanges(Scanner.java:677)
	at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:542)
	at org.eclipse.jetty.util.Scanner.scan(Scanner.java:394)
	at org.eclipse.jetty.util.Scanner$1.run(Scanner.java:345)
	at java.util.TimerThread.mainLoop(Timer.java:512)
	at java.util.TimerThread.run(Timer.java:462)
[INFO] Restart completed at Mon Nov 21 10:13:49 BRST 2011
obrigaod

#10

Eu estou fazendo tudo via annotations... o ruim eh q com o Servlet 2.5 tudo funciona certinho... o problema eh com o servlet 3

obrigado


#11

Eu criei o arquivo e o erro acontece na hra que vou executar alguma operação no banco

2011-11-21 13:50:00.716:WARN::/protocol/protocolo
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'protocoloController': Unsatisfied dependency expressed through constructor argument with index 1 of type [br.com.ig.online.dao.ProtocoloDao]: : Error creating bean with name 'protocoloDao': Unsatisfied dependency expressed through constructor argument with index 0 of type [javax.persistence.EntityManager]: : No matching bean of type [javax.persistence.EntityManager] 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 [javax.persistence.EntityManager] 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.UnsatisfiedDependencyException: Error creating bean with name 'protocoloDao': Unsatisfied dependency expressed through constructor argument with index 0 of type [javax.persistence.EntityManager]: : No matching bean of type [javax.persistence.EntityManager] 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 [javax.persistence.EntityManager] 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:730)
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:196)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1003)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:907)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
	at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:329)
	at org.springframework.web.context.request.AbstractRequestAttributesScope.get(AbstractRequestAttributesScope.java:43)
	....
Caused by: 
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'protocoloDao': Unsatisfied dependency expressed through constructor argument with index 0 of type [javax.persistence.EntityManager]: : No matching bean of type [javax.persistence.EntityManager] 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 [javax.persistence.EntityManager] 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:730)
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:196)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1003)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:907)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
	at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:329)
	at org.springframework.web.context.request.AbstractRequestAttributesScope.get(AbstractRequestAttributesScope.java:43)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:325)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:844)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:786)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
	at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:795)
	...
Caused by: 
org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [javax.persistence.EntityManager] 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:920)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:789)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
	at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:795)
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723)
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:196)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1003)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:907)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
	at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:329)
	at org.springframework.web.context.request.AbstractRequestAttributesScope.get(AbstractRequestAttributesScope.java:43)	
.......

#12

Cara, você confundiu.

O lugar que não precisa mais de XML é no JEE6, para o hibernate, a configuração que o VRaptor usa ainda depende do arquivo de configuração do Hibernate para configurar ele.

Você está usando o JPA ou o Hibernate?

O erro que está dando agora é que ele está tentando injetar um EntityManager no seu DAO.


#13

Estou usando JPA
Estou tentando colocar um autowired mas tb nao ta rolando.. continua o mesmo erro...
o meu DAO final (ProtocoloDao.java) extende deste generio

@Component
public class GenericHibernateDao <T, ID extends Serializable>  {
	private final Class<T> objectClass;
	@Autowired
	private EntityManager manager;
	public GenericHibernateDao(EntityManager manager, Class<T> objectClass) {
		this.manager = manager;
		this.objectClass = objectClass;
	}
	public Class<T> getObjectClass() {
		return objectClass;
	}
	protected Session getSession() {
		return (Session) manager.getDelegate();
	}
	protected Criteria getCriteria() {
		return getSession().createCriteria(objectClass);
	}
	public T find(ID id) {
		return manager.find(objectClass, id);
	}
	@SuppressWarnings("unchecked")
	public T load(ID id) {
		return (T) getSession().load(objectClass, id);
	}
	@SuppressWarnings("unchecked")
	public List<T> findAll() {
		return getCriteria().list();
	}
	public void remove(T obj) {
		manager.remove(manager.merge(obj));
	}
	public T save(T obj) {
		return manager.merge(obj);
	}
	public void setManager(EntityManager manager) {
		this.manager = manager;
	}
	public EntityManager getManager() {
		return manager;
	}
}

primeira vez q to usando o VRaptor e mal ai pelas confusões.

obrigado


#14

Você tem intenção de usar o Spring?

Caso não, tira esse Autowired do código e deixa o VRaptor gerenciar tudo. E vc tbm não precisa do applicationContext.xml

No parametro Packages, vc disse que ia usar o Hibernate?


#15

zoren, muito obrigado pela ajuda e as dicas que me ajudaram a entender o q se passava..
e esse post aq http://www.guj.com.br/java/236684-resolvido-migrando-de-dao-para-repository tb me ajudou a conseguir fazer funcionar as coisas...
bom... vamos as configurações.
1 - sem o arquivo persistence.xml
2 - hibernate.cfg.xml

<?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>  
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.username">xxxx</property>
        <property name="hibernate.connection.password">xxxx</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/xxxx</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
        <property name="hibernate.hbm2ddl.auto">update</property>
        <mapping class="br.com.xxxx.entity.Protocolo" /> 
     </session-factory>  
</hibernate-configuration>

3 - GenericHibernateDao.java

import java.io.Serializable;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
public class GenericHibernateDao <T, ID extends Serializable>  {
	private final Class<T> objectClass;
	private final Session session;
	public GenericHibernateDao(Session session, Class<T> objectClass) {
		this.session = session;
		this.objectClass = objectClass;
	}
	public Class<T> getObjectClass() {
		return objectClass;
	}
	protected Session getSession() {
		return this.session;
	}
	protected Criteria getCriteria() {
		return getSession().createCriteria(objectClass);
	}
	@SuppressWarnings("unchecked")
	public T find(ID id) {
		return (T) this.getSession().load(objectClass, id);
	}
	@SuppressWarnings("unchecked")
	public T load(ID id) {
		return (T) getSession().load(objectClass, id);
	}
	@SuppressWarnings("unchecked")
	public List<T> findAll() {
		return getCriteria().list();
	}
	public void remove(T obj) {
		session.delete(obj);
	}
	@SuppressWarnings("unchecked")
	public T save(T obj) {
		return (T) session.merge(obj);
	}
}

4 - ProtocoloDao.java

@Component
public class ProtocoloDao extends GenericHibernateDao<Protocolo, Long>  {
	public ProtocoloDao(Session session) {
		super(session, Protocolo.class);
	}
	public Protocolo find(Long id, Date data) {
		Calendar instance = Calendar.getInstance();
		instance.setTime(data);
		instance.set(Calendar.DAY_OF_MONTH, 1);
		instance.set(Calendar.HOUR_OF_DAY, 0);
		instance.set(Calendar.MINUTE, 0);
		instance.set(Calendar.SECOND, 0);
		instance.set(Calendar.MILLISECOND, 0);
		return (Protocolo) this.getCriteria().add(
				Restrictions.and(Restrictions.eq("id", id), Restrictions.eq("data", instance.getTime()))
			).uniqueResult();
	}
}

e novamente, obrigado pela ajuda...


#16

vc tem algum component factory de entity Manager? ou pelo menos está usando o pacote ....vraptor.util.jpa no web.xml?


#17