Using quartz in a web application with spring

I created a small console application to see how quartz works and it was easy to create an object applicationcontext

inside the main method to run cron. Ok, now I'm in a real maven managed project that uses cron jobs defined in some of the modules. Each of the modules has its own spring configuration file. I had 3 modules using quartz so it was configured in each of the spring config files. A web application module is one who has a dependency on each of the modules.

Now I had few problems:

  • should i build applicationcontext

    like in console project or should i be loaded. If so, where should I download it.

  • Based on internet research I have done along the line, I am using it MethodInvokingJobDetailFactoryBean

    for easy unit testing. And now that I have to use the class CronExpression

    for testing getNextValidTimeAfter

    , I still don't know how to organize it properly.

Can someone give me a hand. I would really appreciate it. Thanks for reading

+2


source to share


1 answer


As per the comment, the question is closer to "How to load a Spring application context file for a web application".

According to Section 3.8.5, "Convenient ApplicationContext Instance for Web Applications" , you can register ApplicationContext

with the ContextLoaderListener

following (add this to your file web.xml

):



<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/daoContext.xml /WEB-INF/applicationContext.xml</param-value>
</context-param>

<listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- or use the ContextLoaderServlet instead of the above listener
<servlet>
  <servlet-name>context</servlet-name>
  <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>
-->

      

+4


source







All Articles