Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7836359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:06:40+00:00 2026-06-02T14:06:40+00:00

I am using Quartz Scheduler with my spring 3.0 based application. I am successfully

  • 0

I am using Quartz Scheduler with my spring 3.0 based application. I am successfully able to create new schedulers and they are working fine.

I have seen thus reference.

But.. I am not able to retrieve servletContext in my quartz job file. can anyone help me for How to retrieve servletContext reference in executeInternal() method ??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T14:06:41+00:00Added an answer on June 2, 2026 at 2:06 pm

    I had a similar need. I sorted it out in a similar fashion to the solution presented here.
    In my servlet context listener I am setting the servlet context using the job data map object which then is set for a job:

        @Override
        public void contextInitialized(ServletContextEvent sce) {
            try {
                //Create & start the scheduler.
                StdSchedulerFactory factory = new StdSchedulerFactory();
                factory.initialize(sce.getServletContext().getResourceAsStream("/WEB-INF/my_quartz.properties"));
                scheduler = factory.getScheduler();
                //pass the servlet context to the job
                JobDataMap jobDataMap = new JobDataMap();
                jobDataMap.put("servletContext", sce.getServletContext());
                // define the job and tie it to our job's class
                JobDetail job = newJob(ImageCheckJob.class).withIdentity("job1", "group1").usingJobData(jobDataMap).build();
                // Trigger the job to run now, and then repeat every 3 seconds
                Trigger trigger = newTrigger().withIdentity("trigger1", "group1").startNow()
                      .withSchedule(simpleSchedule().withIntervalInMilliseconds(3000L).repeatForever()).build();
                // Tell quartz to schedule the job using our trigger
                scheduler.scheduleJob(job, trigger);
                // and start it off
                scheduler.start();
            } catch (SchedulerException ex) {
                log.error(null, ex);
            }
        }
    

    Then inside my job I am doing this:

        @Override
        public void execute(JobExecutionContext context) throws JobExecutionException {
            ServletContext servletContext = (ServletContext) context.getMergedJobDataMap().get("servletContext");
            //...
        }
    

    EDIT:
    Also since you mention that you are using Spring I found this link, where in the last post a guy mentions to implement ServletContextAware. Personally, I would go with the JobDataMap, since that is its role.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using quartz scheduler in my spring project. I have to run a
I'm using Spring's SchedulerFactoryBean to run some Quartz jobs within a Spring based java
I'm using Spring to inject a Quartz scheduler (abstracted with Spring's TaskScheduler interface) into
I am using asp.net mvc 3 and quartz scheduler. Currently I have this A
I need to configure a Quartz.NET instance using Spring.NET. I haven't been able to
I'm trying to implement scheduler to my application. I use spring and quartz support.
I am using Quartz Scheduler using Spring. I want to configure the same with
I have an issue with quartz library. I'm using it with spring 2.5: <bean
it is a interesting question. i am using Quartz.net to make job scheduler. also
I am using quartz.net to schedule regular events within asp.net mvc application. The scheduled

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.