Olá pessoa!
Tenho uma classe anotada com @Component:
@Component
public class ParameterLoader {
private final String PROPERTIES_NAME = "param.properties";
private PropertiesLoader propertiesLoader;
public ParameterLoader(ServletContext servletContext) {
try {
this.propertiesLoader = new PropertiesLoader(new FileInputStream(new File(servletContext.getRealPath("/WEB-INF/properties/" + this.PROPERTIES_NAME))));
} catch (Exception exception) {
throw new RuntimeException(exception);
}
}
public String getParameter(String parameterName) {
return this.propertiesLoader.getValue(parameterName);
}
}
Esta classe é injetada na classe MyFirstApplicationTask que está anotada com @AplicationScoped
@Component
@ApplicationScoped
public class MyFirstApplicationTask implements ApplicationTask {
private News news;
private ParameterLoader parameterLoader;
public MyFirstApplicationTask(TaskScheduler scheduler, News news,ServletContext servletContext,
ParameterLoader parameterLoader) {
this.schedule(scheduler);
this.news = news;
this.parameterLoader = new ParameterLoader(servletContext);
}
public void schedule(TaskScheduler scheduler) {
String agenda = this.parameterLoader.getParameter("scheduler.mail");
scheduler.schedule(this, new CronTrigger(agenda));
}
public void run(){
news.enviar();
}
}
A exceção é:
00:35:24,785 INFO [DefaultListableBeanFactory] Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@407166: defining beans [pathAnnotationRoutesParser,encodingHandlerFactory,hibernateProxyInitializer,defaultDeserializers,paranamerNameProvider,asmBasedTypeCreator,JSR303ValidatorFactory,defaultConverters,defaultMultipartConfig,objenesisProxifier,defaultInterceptorHandlerFactory,defaultAcceptHeaderToFormat,validatorFactoryCreator,noRoutesConfiguration,defaultInterceptorRegistry,defaultMethodNotAllowedHandler,defaultRoutes,XStreamXMLDeserializer,defaultResourceNotFoundHandler,defaultTypeNameExtractor,defaultRouter,messageInterpolatorFactory,defaultTypeFinder,defaultRestDefaults,defaultResourceTranslator,stereotypeHandler,converterHandler,interceptorStereotypeHandler,deserializesHandler,stereotypedBeansRegistrar,defaultSpringLocator,downloadInterceptor,flashInterceptor,emptyResult,outjectResult,jstlLocalization,applicationConfiguration,defaultValidationViewsFactory,instantiateInterceptor,defaultRepresentationResult,JSR303Validator,forwardToDefaultViewInterceptor,defaultLogicResult,interceptorListPriorToExecutionExtractor,XStreamXMLSerialization,defaultFormatResolver,emptyElementsRemoval,exceptionHandlerInterceptor,ognlParametersProvider,parametersInstantiatorInterceptor,deserializingInterceptor,commonsUploadMultipartInterceptor,defaultResult,defaultRefererResult,defaultRestHeadersHandler,defaultExceptionMapper,defaultValidator,defaultMethodInfo,jsonDeserializer,resourceLookupInterceptor,replicatorOutjector,HTMLSerialization,defaultHttpResult,XStreamJSONSerialization,defaultStatus,executeMethodInterceptor,defaultPathResolver,defaultPageResult,primitiveIntConverter,uploadedFileConverter,primitiveByteConverter,doubleConverter,primitiveBooleanConverter,primitiveFloatConverter,primitiveCharConverter,localeBasedDateConverter,byteConverter,primitiveLongConverter,booleanConverter,localeBasedCalendarConverter,primitiveDoubleConverter,bigIntegerConverter,enumConverter,longConverter,characterConverter,integerConverter,bigDecimalConverter,shortConverter,primitiveShortConverter,floatConverter,VRaptorRequestProvider,httpServletRequestProvider,httpServletResponseProvider,httpSessionProvider,defaultInterceptorStack,defaultRequestExecution,entityManagerCreator,entityManagerFactoryCreator,JPATransactionInterceptor,noCacheInterceptor,relatorioDAO,usuarioDAO,fotoDAO,modalidadeDAO,tipoDAO,statusDAO,proprietarioDAO,roleDAO,contatoDAO,imovelDAO,municipioDAO,imagens,busca,jasperMaker,myFirstRequestTask,sendMail,customMultipartConfig,newsletter,parameterLoader,taskSchedulerFactory,myFirstApplicationTask,news,contatoController,proprietarioController,fotoController,municipioController,usuarioController,empresaController,tasksController,relatoriosController,modalidadeController,statusController,loginController,imovelController,indexController,homeController,tipoController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,localeBasedDoubleConverter,localeBasedBigDecimalConverter,localeBasedFloatConverter,org.springframework.aop.config.internalAutoProxyCreator,cacheBasedTypeCreator]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@6c1a82
00:35:24,786 INFO [ThreadPoolTaskScheduler] Shutting down ExecutorService
09/12/2010 00:35:24 org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter vraptor
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myFirstApplicationTask' defined in file [/home/bruno/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/imobiliaria/WEB-INF/classes/br/com/imobiliaria/component/MyFirstApplicationTask.class]: Unsatisfied dependency expressed through constructor argument with index 3 of type [br.com.imobiliaria.component.ParameterLoader]: : Error creating bean with name 'parameterLoader': 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 'parameterLoader': 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:718)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:194)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:993)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:897)
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:574)
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:68)
at br.com.caelum.vraptor.ioc.spring.SpringProvider.start(SpringProvider.java:82)
at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:110)
at br.com.caelum.vraptor.VRaptor.init(VRaptor.java:103)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:269)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:250)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:368)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:98)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4193)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4801)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:988)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:771)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:988)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:275)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:427)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:649)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at org.apache.catalina.startup.Catalina.start(Catalina.java:585)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:415)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'parameterLoader': 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:339)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:838)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:780)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:697)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:784)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:711)
... 40 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:123)
at org.springframework.web.context.request.AbstractRequestAttributesScope.get(AbstractRequestAttributesScope.java:40)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:325)
... 46 more
09/12/2010 00:35:24 org.apache.catalina.core.StandardContext startInternal
SEVERE: Error filterStart
09/12/2010 00:35:24 org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/imobiliaria] startup failed due to previous errors
09/12/2010 00:35:24 org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
00:35:24,800 INFO [XmlWebApplicationContext] Closing Root WebApplicationContext: startup date [Thu Dec 09 00:35:21 BRST 2010]; root of context hierarchy
00:35:24,801 INFO [DefaultListableBeanFactory] Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@6c1a82: defining beans [org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler#0,org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource#0,org.springframework.security.access.vote.AffirmativeBased#0,org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor#0,org.springframework.security.methodSecurityMetadataSourceAdvisor,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.security.web.PortMapperImpl#0,org.springframework.security.web.context.HttpSessionSecurityContextRepository#0,org.springframework.security.core.session.SessionRegistryImpl#0,org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy#0,org.springframework.security.authentication.ProviderManager#0,org.springframework.security.access.vote.AffirmativeBased#1,org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0,org.springframework.security.web.access.DefaultWebInvocationPrivilegeEvaluator#0,org.springframework.security.authentication.AnonymousAuthenticationProvider#0,org.springframework.security.web.savedrequest.HttpSessionRequestCache#0,org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint#0,org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0,org.springframework.security.config.http.UserDetailsServiceInjectionBeanPostProcessor#0,org.springframework.security.filterChainProxy,org.springframework.security.provisioning.JdbcUserDetailsManager#0,org.springframework.security.authentication.dao.DaoAuthenticationProvider#0,org.springframework.security.authentication.DefaultAuthenticationEventPublisher#0,org.springframework.security.authenticationManager,dataSource]; root of factory hierarchy
09/12/2010 00:35:24 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [/imobiliaria] registered the JBDC driver [org.postgresql.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
09/12/2010 00:35:24 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/imobiliaria] appears to have started a thread named [com.google.common.base.internal.Finalizer] but has failed to stop it. This is very likely to create a memory leak.
Onde eu estou errando? =/
Abraço!