Olá, possuo a seguinte estrutura de módulos em um projeto maven:
manager(maven project)
- webresources(maven module[vraptor])
- domain(maven module[jpa])
- custom_server(maven module)
Essa estrutura é toda executada a partir do módulo webresources que é publicado no tomcat.
E meu problema é que precisava injetar dependências no webresources de classes que estão nos outros dois módulos e que eu as enxergo como componentes(@Component).
Estou usando a implementação padrão do Spring no projeto e vi que para que o mesmo reconhecesse código externo ao web-inf/classes seria necessário setar:
<context-param>
<param-name>br.com.caelum.vraptor.packages</param-name>
<param-value>br.com.meupacote</param-value>
</context-param>
Isso resolve bem o problema, no entanto eu possuo dois projetos, logo precisaria setar 2 diretórios diferentes. O que invalida a solução.
Dessa forma resolvi criar meu próprio factory provider da seguinte maneira:
public class FactoryProvider extends SpringProvider {
@Override
public void registerCustomComponents( ComponentRegistry registry ) {
registry.register( EntityManagerCreator.class, EntityManagerCreator.class );
registry.register( EntityManagerFactoryCreator.class, EntityManagerFactoryCreator.class );
registry.register( UserLogicCreator.class, UserLogicCreator.class ); //do domain module
registry.register( TokenConfigCreator.class, TokenConfigCreator.class ); //do custom_server module
}
}
E o web.xml
<context-param>
<param-name>br.com.caelum.vraptor.provider</param-name>
<param-value>br.com.meupacote.FactoryProvider</param-value>
</context-param>
As 3 primeiras fábricas são sequencialmente(RequestScoped,ApplicationScoped e RequestScoped), de forma que toda instância de UserLogic é composta por um EntityManager.
Só que não está funcionando. O erro que recebo é:
core.StandardContext filterStart
Grave: Exception starting filter vraptor
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'tokenConfigCreator': Unsatisfied dependency expressed through constructor argument with index 0 of type [com.neoex.domain.logic.UserLogic]: : Error creating bean with name 'com.neoex.factory.UserLogicCreator': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userLogicCreator': 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 'com.neoex.factory.UserLogicCreator': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userLogicCreator': 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: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$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:108)
at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:102)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:273)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:254)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:372)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:98)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4562)
at org.apache.catalina.core.StandardContext$2.call(StandardContext.java:5240)
at org.apache.catalina.core.StandardContext$2.call(StandardContext.java:5235)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Eu vi que o meu provider é chamado no init do projeto mas mesmo assim ele não ta dando conta de resolver as dependências.
Alguma idéia?