Skip to content
This repository was archived by the owner on Dec 2, 2021. It is now read-only.
This repository was archived by the owner on Dec 2, 2021. It is now read-only.

Defining a job as a prototype scoped bean causes a cyclic dependency on startup #11

@longwa

Description

@longwa

If you define a bean that implements SchwartzJob as prototype scoped in resources.groovy

    'testJob'(TestJob) { bean ->
        bean.scope = 'prototype'
    }

You will get the following on startup:

The dependencies of some of the beans in the application context form a cycle:

┌─────┐
|  testJob (field private com.agileorbit.schwartz.QuartzService schwartztest.TestJob.com_agileorbit_schwartz_SchwartzJob__quartzService)
↑     ↓
|  schwartzQuartzService (field protected com.agileorbit.schwartz.SchwartzJob[] com.agileorbit.schwartz.QuartzService.jobs)
└─────┘

I guess in the singleton case, the beans injected into the job array don't need to be initialize again, so it works.

The fix is simple, the quartzService reference in SchwartzJob just needs to be annotated with @Lazy:

@Lazy @Autowired QuartzService quartzService

Simple project to reproduce:
https://github.com/longwa/grails-schwartzTest

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions