Veja bem… fiz a apostila FJ28 e agora estou implementando novas coisas. Por exemplo envio de email automatico com o Vraptor-Tasks.
Aí vai minha dúvida:
Por exemplo, para o historicoController acessar o HistoricoDao, pelo que eu intendi, ele apenas anota a classe com @Resource e @Component, e tudo funciona perfeitamente:
[code]@Resource
public class HistoricosController {
private HistoricoDao dao;
private final Result result;
private Validator validator;
public HistoricosController(HistoricoDao dao, Result result,
Validator validator) {
this.dao = dao;
this.result = result;
this.setValidator(validator);
}
@Restrito
@Get("/historico")
public List<Historico> lista() {
return dao.listaTudo();
}
public List<Historico> busca(String titular) {
result.include("titular", titular);
return dao.busca(titular);
}
… . . . . .
@Component
public class HistoricoDao {
private final Session session;
public HistoricoDao(Session session) {
this.session = session;
}
public void salva(Historico historico) {
Transaction tx = session.beginTransaction();
session.save(historico);
tx.commit();
}
public void atualiza(Historico historico) {
Transaction tx = session.beginTransaction();
this.session.update(historico);
tx.commit();
}
…
[/code]
Agora quero fazer uma busca a partir da classe schedulada pelo Vraptor-Tasks, e não tenho idéia de como fazer… Pensei que era soh fazer isso aqui oh:
[code]
@Resource
@ApplicationScoped
@Scheduled(fixedRate = 21600000, concurrent = false)
public class EmailLigacoes implements Task {
private HistoricoDao dao;
public EmailLigacoes(HistoricoDao dao) {
this.dao = dao;
}
…[/code]
mas não funcionou… ele retorna o seguinte erro no start do server:
SEVERE: Exception starting filter vraptor
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'taskHandler': Unsatisfied dependency expressed through constructor argument with index 1 of type [java.util.List]: : Error creating bean with name 'emailLigacoes': Unsatisfied dependency expressed through constructor argument with index 0 of type [br.com.ajm.scdri.dao.HistoricoDao]: : Error creating bean with name 'historicoDao': 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 'historicoDao': 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.UnsatisfiedDependencyException: Error creating bean with name 'emailLigacoes': Unsatisfied dependency expressed through constructor argument with index 0 of type [br.com.ajm.scdri.dao.HistoricoDao]: : Error creating bean with name 'historicoDao': 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 'historicoDao': 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: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:4656)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5309)
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)
OU SERIA MELHOR no construtor colocar a classe Controller invés do DAO???
quero fazer um simples dao.Busca(new Date());
e então???.. =)