2

So, I faced this issue which I wasn't even aware that could happen. So far my understanding is JVM identifies class with a combination of class-name,package-name and the classloader name. I have verified that all of these 3 are matching and still I am getting ClassCastException.

@Component
public class SomeBean(){
//this is my service
}

I am able to successfully inject it using spring autowired in of my classes where I inject it into the Quartz Scheduler's context which looks something like:

scheduler.getContext().put("Key",SomeBeanInstance);

I am trying to fetch this bean inside my Quartz Job's execute method which roughly looks like following:

SomeBean someBeanInstance = (SomeBean) schedulerContext.get("key");

This gives me class cast exception along the lines of: cannot cast a.b.SomeBean to a.b.SomeBean. I verified classLoader both at my class where someBean is injected and Quartz job and it's the same. It is RestartClassLoader (org.spring.devtools)

How do I fix this issue?

Is there a better way to inject service beans into a quartz job?

Sudip Bhandari
  • 2,165
  • 1
  • 27
  • 26

0 Answers0