Erro: Creating bean with name 'entityManagerCreator'

274 views
Skip to first unread message

Daniele LeĂŁo Evangelista

unread,
Aug 22, 2013, 1:49:17 PM8/22/13
to caelum-...@googlegroups.com
Pessoal, estou tentando utilizar vraptor com spring, mas estou tendo o seguinte erro:

http://pastebin.com/YJFKWJLW

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'loginDAOImpl': Unsatisfied dependency expressed through constructor argument with index 0 of type [javax.persistence.EntityManager]: : Error creating bean with name 'br.com.caelum.vraptor.util.jpa.EntityManagerCreator': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerCreator': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'br.com.caelum.vraptor.util.jpa.EntityManagerCreator': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerCreator': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
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:1045)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:949)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:910)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:853)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:768)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486)
... 29 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'br.com.caelum.vraptor.util.jpa.EntityManagerCreator': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerCreator': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:149)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:109)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1454)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:249)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:910)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:853)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:768)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:795)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723)
... 42 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerCreator': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:343)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:273)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1125)
at br.com.caelum.vraptor.ioc.spring.SpringBasedContainer.instanceFor(SpringBasedContainer.java:86)
at br.com.caelum.vraptor.ioc.spring.ComponentFactoryBean.getObject(ComponentFactoryBean.java:43)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)
... 51 more
Caused by: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:131)
at org.springframework.web.context.request.AbstractRequestAttributesScope.get(AbstractRequestAttributesScope.java:40)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:329)
... 57 more

Alguém poderia me dar uma ajuda?

Carlos Alberto Junior Spohr Poletto

unread,
Aug 22, 2013, 2:16:39 PM8/22/13
to caelum-...@googlegroups.com
Não está faltando um @Component nessa classe 'loginDAOImpl'


--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to caelum-vrapto...@googlegroups.com.
To post to this group, send email to caelum-...@googlegroups.com.
Visit this group at http://groups.google.com/group/caelum-vraptor.
For more options, visit https://groups.google.com/groups/opt_out.



--
Atenciosamente,
Carlos Alberto Junior Spohr Poletto

Daniele LeĂŁo Evangelista

unread,
Aug 22, 2013, 2:27:57 PM8/22/13
to caelum-...@googlegroups.com
Carlos, ela está anotada já com @Component

Daniele LeĂŁo Evangelista

unread,
Aug 22, 2013, 2:49:06 PM8/22/13
to caelum-...@googlegroups.com
Coloquei @Resource na minha classe e agora o erro que dá é esse

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.customAuthenticationProvider': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private br.com.indra.igia.dao.database.PasswordDAO br.com.indra.igia.security.auth.CustomAuthenticationProvider.passwordDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'passwordDAOImpl': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1116)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
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:108)
at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:102)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:281)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:262)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:107)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4775)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5452)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private br.com.indra.igia.dao.database.PasswordDAO br.com.indra.igia.security.auth.CustomAuthenticationProvider.passwordDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'passwordDAOImpl': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:514)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
... 27 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'passwordDAOImpl': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:343)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:910)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:853)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:768)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486)
... 29 more
Caused by: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:131)
at org.springframework.web.context.request.AbstractRequestAttributesScope.get(AbstractRequestAttributesScope.java:40)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:329)
... 34 more

Só pra explicar melhor. Eu to usando Spring Security e Vraptor no meu projeto. O spring security chama uma classe de autenticação que não é anotada com nada... dentro dessa minha classe eu preciso acessar um DAO. Estou tentando utilizar o @Autowired, mas ele não funciona... Eu tentei anotar minha classe como @Resource, as dá o erro acima!

Otávio Garcia

unread,
Aug 22, 2013, 2:50:38 PM8/22/13
to caelum-...@googlegroups.com
Deve ser @Component. @Resource Ă© apenas para controllers.

Essa classe está no projeto ou em um outro jar?


--

Daniele LeĂŁo Evangelista

unread,
Aug 22, 2013, 3:02:53 PM8/22/13
to caelum-...@googlegroups.com
Otavio, já tentei colocar como @Component, mas o erro é o mesmo. 

Essa classe está dentro de um jar... Tem alguma coisa???

Otávio Garcia

unread,
Aug 22, 2013, 3:13:03 PM8/22/13
to caelum-...@googlegroups.com
Sim. O VRaptor só faz scan automatico se as classes estiverem nas classes do projeto (WEB-INF/classes). As que estão dentro de um jar há duas formas:

- Adicionando o parametro br.com.caelum.vraptor.packages no web.xml
- Adicionado um arquivo META-INF/br.com.caelum.vraptor.packages com o nome dos pacotes

Aqui tem uma explicação: http://vraptor.caelum.com.br/pt/docs/componentes-utilitarios-opcionais/

Daniele LeĂŁo Evangelista

unread,
Aug 22, 2013, 3:42:06 PM8/22/13
to caelum-...@googlegroups.com
Acho que estou QUASE lá...  Agora o que está acontecendo é que ele não injeta meu Dao... Está vindo null =/

Otávio Garcia

unread,
Aug 22, 2013, 4:24:17 PM8/22/13
to caelum-...@googlegroups.com
Não consigo imaginar porque ele viria null. Vocẽ está injetando a interface ou a classe de implementação?

Daniele LeĂŁo Evangelista

unread,
Aug 22, 2013, 4:41:54 PM8/22/13
to caelum-...@googlegroups.com
Injetando a interface. 
Mas creio que seja problema com o spring security. Parece q ele nĂŁo funciona legal com o vraptor

Lucas Cavalcanti

unread,
Aug 22, 2013, 4:48:20 PM8/22/13
to caelum-vraptor
O spring security funciona bem com o VRaptor sim...

a dependência que vc tá recebendo no construtor ta vindo nula no construtor?
ela tá declarada no vraptor ou no spring?

vc tem uma componentFactory ou coisa do tipo que constroi essa dependencia?

Daniele LeĂŁo Evangelista

unread,
Aug 22, 2013, 5:17:59 PM8/22/13
to caelum-...@googlegroups.com
Lucas eu já tentei colocar ela pra ser injetada com o @Autowired, para ser injetada no construtor, e ambos jeitos ela vem null. 

O meu DAO está declarado no vraptor, o meu CustomProvider está anotado (agora) no vraptor. Já tentei colocar tanto no vraptor como no spring. 
NĂŁo possuo nenhum componentFactory

Lucas Cavalcanti

unread,
Aug 22, 2013, 5:55:17 PM8/22/13
to caelum-vraptor
não faz sentido ele injetar null na dependência que vc recebeu no construtor... tem certeza que é isso que ele está fazendo mesmo?

o que Ă© o seu CustomProvider?

aparece algo no log?

essa é a classe que vc tá usando pra implementar a interface de usuario do spring security?

Daniele LeĂŁo Evangelista

unread,
Aug 23, 2013, 8:36:31 AM8/23/13
to caelum-...@googlegroups.com
Lucas, para dar continuidade no projeto, eu fiz um "arame" pra eu conseguir fazer o resto, mas seria legal se eu conseguisse resolver isso... Eu vou postar minha classe pra ver se vocĂŞ consegue entender ok?

Eu tenho a minha classe CustomAuthenticationProvider que é usada para autenticar o usuário no sistema

http://pastebin.com/mt3cZc56 ( classe CustomAuthenticationProvider )

O que eu estou tentando fazer Ă© que o meus DAOs sejam injetados ...

http://pastebin.com/LEUSmiVc Essa é a implementação do meu DAO... 

O estranho Ă© que eu estava usando o Spring para fazer tudo, e aĂ­ funcionava, mas agora a parte de persistence foi mudada para utilizar vraptor e aĂ­ nĂŁo consigo mais utilizar =(

Seria fantástico se conseguisse arrumar isso rs....

Lucas Cavalcanti

unread,
Aug 23, 2013, 9:28:39 AM8/23/13
to caelum-vraptor
vc está com o applicationContext.xml com esse nome e no classpath?

vc tá registrando ele num ContextLoaderListener?

vc tá com uma versão atual do VRaptor?

Daniele LeĂŁo Evangelista

unread,
Aug 23, 2013, 10:27:11 AM8/23/13
to caelum-...@googlegroups.com
Sim para todas as perguntas rs..

Meu web.xml está assim 

Lucas, eu fui dar um clean no meu projeto e agora quando subo está dando esse erro:

java.lang.IllegalArgumentException: You don't have any DI container jars on your classpath. You can find them on vraptor-3.x.x.zip, so you must put one of the lib/containers/<container> jars on your classpath, where <container> is your preferred container.
at br.com.caelum.vraptor.config.BasicConfiguration.getProviderType(BasicConfiguration.java:101)
at br.com.caelum.vraptor.config.BasicConfiguration.getProvider(BasicConfiguration.java:70)
at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:102)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:281)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:262)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:107)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4775)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5452)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Daniele LeĂŁo Evangelista

unread,
Aug 23, 2013, 11:00:49 AM8/23/13
to caelum-...@googlegroups.com
Lucas o problema do DI Container ja resolvi. Agora sĂł o resto que nĂŁo rs

Lucas Cavalcanti

unread,
Aug 23, 2013, 12:27:48 PM8/23/13
to caelum-vraptor
Acho que sei qual Ă© o problema...

declare o filtro do VRaptor no web.xml ANTES do filtro do spring security...

o que deve estar acontecendo Ă© que o spring security roda antes do VRAptor, daĂ­ as classes do VRaptor ainda nĂŁo foram instanciadas.

Daniele LeĂŁo Evangelista

unread,
Aug 23, 2013, 12:44:56 PM8/23/13
to caelum-...@googlegroups.com
Lucas, quando vocĂŞ diz pra declarar o filtro do Vraptor antes, vocĂŞ diz que deixar assim

<context-param>
   <param-name>br.com.caelum.vraptor.packages</param-name>
   <param-value>
       br.com.caelum.vraptor.util.jpa,
       br.com.indra.igia.dao.database.impl,
       br.com.indra.igia.security.auth
   </param-value>
</context-param>

É isso??

Uma dúvida, esse  <param-name>br.com.caelum.vraptor.packages</param-name> substitui o 

<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>

Lucas Cavalcanti

unread,
Aug 23, 2013, 2:06:59 PM8/23/13
to caelum-vraptor
o parametro de packages Ă© uma coisa, o <filter> Ă© outra... estava falando de colocar o <filter> do vraptor no web.xml e antes do filtro do spring security.

Daniele LeĂŁo Evangelista

unread,
Aug 23, 2013, 2:19:05 PM8/23/13
to caelum-...@googlegroups.com

Lucas, deixei meu web.xml assim

mas ainda continua dando null... 

O engraçado é que se eu coloco isso no meu applicationContext: <context:annotation-config /><context:component-scan base-package="br.com.xxx.xxx" /> ele dá o seguinte erro http://pastebin.com/hZJM8yXm . Eu sei que é erro de configuração, mas não encontro o caminho certo.  O que achei  estranho Lucas é que eu fiz um teste. Eu criei uma classe anotada com @Service do Spring e tentei dar um @Autowired, e foi. Me parece que ele não está conseguindo conversar spring com vraptor... O que não deveria acontecer pois como você disse, vraptor no fundo usa spring =/

Lucas Cavalcanti

unread,
Aug 23, 2013, 2:37:54 PM8/23/13
to caelum-vraptor
Habilita o log de debug do VRaptor e ve o que aparece na inicialização do sistema... ele deve falar que está usando o contexto do spring.

Daniele LeĂŁo Evangelista

unread,
Aug 23, 2013, 2:50:14 PM8/23/13
to caelum-...@googlegroups.com
Lucas, habilite ele, mas não encontrei nada que mostre que ele esta usando o contexto do spring. Pode me ajudar? O log foi esse http://pastebin.com/BzdXptEN

Otávio Garcia

unread,
Aug 23, 2013, 2:54:39 PM8/23/13
to caelum-...@googlegroups.com
Daniele, e se você colocar a classe dentro do projeto ao invés de colocar dentro de um jar?

Faça um teste assim, só para termos uma idéia se é algo da classe estar em outro projeto.

Daniele LeĂŁo Evangelista

unread,
Aug 23, 2013, 2:57:48 PM8/23/13
to caelum-...@googlegroups.com
Já tentei Otavio rs...
Uma das primeiras coisas que fiz foi tentar colocar a classe dentro do projeto para ver se funcionava, mas também não funcionou.

Otávio Garcia

unread,
Aug 23, 2013, 3:09:33 PM8/23/13
to caelum-...@googlegroups.com
Estou achando estranho, porque no log ele fez o scanning da classe. Porém aparentemente ele não fez o pareamento de LoginDAO para LoginDAOImpl, mas sim LoginDAOImpl para LoginDAOImpl.

Daniele LeĂŁo Evangelista

unread,
Aug 23, 2013, 3:21:04 PM8/23/13
to caelum-...@googlegroups.com
Então Otavio, o estranho é que se eu faço o @Autowired em alguma classe anotada com Spring ele vai, mas com Vraptor, não... =/ e preciso usar o vraptor

Lucas Cavalcanti

unread,
Aug 23, 2013, 3:59:01 PM8/23/13
to caelum-vraptor
Daniele, faça o seguinte:

coloque o <listener> antes das declarações dos filtros.

coloque required=false no login dao:

@Autowired(required=false)
private LoginDAO dao;


O problema Ă© que qdo vc declara o listener ele sobe todo o contexto do spring, antes de registrar as coisas do VRaptor.

qdo vc coloca esse required=false dá tempo do VRaptor registrar suas dependências antes.

Tenta aí... se ainda assim não funcionar tem outra solução possível.

Daniele LeĂŁo Evangelista

unread,
Aug 23, 2013, 4:16:46 PM8/23/13
to caelum-...@googlegroups.com
Lucas,

Continua dando null o @Autowired... Ve se isso tem alguma coisa a ver, o meu CustomAuthenticationProvider está declarado dentro do meu applicationContext.xml  da seguinte forma:

<bean id="customAuthenticationProvider" scope="request"
class="br.com.indra.igia.provider.CustomAuthenticationProvider">
<aop:scoped-proxy/>
</bean>

Aí ele roda, mas o @Autowired fica null... Porém se eu tiro esse scope="request" ele da esse erro: http://pastebin.com/xju2QgUF

Lucas, me perdoa por estar te enchendo tanto. É que já fiz tanta configuração que nem sei mais  o que fazer =/

Lucas Cavalcanti

unread,
Aug 23, 2013, 4:21:21 PM8/23/13
to caelum-vraptor
Tenta deixar seu web.xml assim:


e mova o applicationContext.xml pra sua pasta src/main/resources

Daniele LeĂŁo Evangelista

unread,
Aug 23, 2013, 4:39:14 PM8/23/13
to caelum-...@googlegroups.com
Lucassss... mew, vocĂŞ salvou minha vida =']

Era isso mesmo. Agora está funcionando redondinho =] ... 

Mas, qual o motivo de ele nĂŁo funcionar com os listern?

Lucas Cavalcanti

unread,
Aug 23, 2013, 4:41:15 PM8/23/13
to caelum-vraptor
o problema é que o listener inicializa antes do VRaptor... e qdo ele inicializa ele já valida todos os objetos do spring.

o VRaptor até aproveita os componentes registrados no listener, mas ele faz isso depois e reinicializa o Spring... nesse momento pode dar o problema que vc passou.

qdo vc deixa o applicationContext.xml no classpath, o VRaptor já inicializa o contexto do spring logo de cara, daí não dá problemas.

Daniele LeĂŁo Evangelista

unread,
Aug 23, 2013, 4:48:20 PM8/23/13
to caelum-...@googlegroups.com
Entendi. Nossa, pensei que ia ter que ficar quebrando minha cabeça dias aqui. To começando a mexer agora tanto com vraptor como com spring security aí ainda fico perdida nas configurações, mas espero não ter mais problemas =]
Reply all
Reply to author
Forward
0 new messages