File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes Spring with Quartz Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring with Quartz" Watch "Spring with Quartz" New topic
Author

Spring with Quartz

MichaelJ McCabe
Ranch Hand

Joined: Feb 09, 2010
Posts: 49
I have been ripping my hair out for a while with quartz just not working within my application. Being quite new to even Spring, I was hoping I am missing something simple and could be helped out. I have looked at online tutorials and even the spring in action book. But for some reason within my application it will not work.

I have a simple class



and within my application-context (which I know is working with other beans)



That should be priting out the line over and over on the console, but its not. Any ideas?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Is the misspelling of "property" a typo?
MichaelJ McCabe
Ranch Hand

Joined: Feb 09, 2010
Posts: 49
David Newton wrote:Is the misspelling of "property" a typo?


Good eyes ;)

Yes it is, but only pasting here. In my code its spelt correctly... and double checked :P
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

How do you execute your application ? How do your read the context file ?


[My Blog]
All roads lead to JavaRanch
MichaelJ McCabe
Ranch Hand

Joined: Feb 09, 2010
Posts: 49
Christophe Verré wrote:How do you execute your application ? How do your read the context file ?


I have my web.xml file with



David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I think the question was more "How are you initializing Spring?"
MichaelJ McCabe
Ranch Hand

Joined: Feb 09, 2010
Posts: 49
David Newton wrote:I think the question was more "How are you initializing Spring?"


Right ok. Like I said, my spring knowledge is limited but I am using ContextLoaderServlet

MichaelJ McCabe
Ranch Hand

Joined: Feb 09, 2010
Posts: 49
I am getting this -

Error creating bean with name 'myJob' defined in ServletContext resource [/WEB-INF/applicationContext-hibernate.xml]:

Error setting property values; nested exception is org.springframework.beans.PropertyAccessExceptionsException: PropertyAccessExceptionsException (1 errors); nested propertyAccessExceptions are: [org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [java.lang.Class] for property 'jobClass'; nested exception is java.lang.IllegalArgumentException: Class not found: MyJob
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

You're telling Spring that there is a JobDetailBean class called Myjob in the "path" package. Is the MyJob class in a package called "path" ? I don't see any package declaration in your code.
MichaelJ McCabe
Ranch Hand

Joined: Feb 09, 2010
Posts: 49
Christophe Verré wrote:You're telling Spring that there is a JobDetailBean class called Myjob in the "path" package. Is the MyJob class in a package called "path" ? I don't see any package declaration in your code.


the "path" was just filled in as the path was really long. So although it wasnt specifically that, it turned out it was a path problem... which is quite embarasing.

But it brings me onto a simular question;

I want to reference a bean within the quartz job. Its a bean which is defined in my Struts-config, with its own action. Is this possible? The bean is as follows


David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That's no bean, that's an action. Spring knows nothing about it.

Struts actions can be Spring beans (or vice-versa, depending on your point of view), but the action class itself would need to be defined as a Spring bean. There's Struts 1-Spring integration, so this is not a big deal.

That said: that's a *bad* idea, there should be no reason why a Quartz job would need to access a Struts action, unless something has gone wrong with your design: that's an inappropriate coupling.
MichaelJ McCabe
Ranch Hand

Joined: Feb 09, 2010
Posts: 49
David Newton wrote:That's no bean, that's an action. Spring knows nothing about it.

Struts actions can be Spring beans (or vice-versa, depending on your point of view), but the action class itself would need to be defined as a Spring bean. There's Struts 1-Spring integration, so this is not a big deal.

That said: that's a *bad* idea, there should be no reason why a Quartz job would need to access a Struts action, unless something has gone wrong with your design: that's an inappropriate coupling.



Ok Thanks for the clear up. I'm very new to all this.

The reason I was to access a Struts action is as follows. Due to my lack of knowledge, I cannot think of a better way.

Within this quartz job, i want access to my SpringHibernateDao. Now I do this using



and my service finder



this is the ONLY way I know of doing this. And it requires a HttpServletRequest. And the only way I know of having that is through a struts action
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Inject the DAO directly into your Quartz job--that's what Spring is for; why convolute things?
MichaelJ McCabe
Ranch Hand

Joined: Feb 09, 2010
Posts: 49
David Newton wrote:Inject the DAO directly into your Quartz job--that's what Spring is for; why convolute things?


How would I go about doing this?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Define the DAO bean in Spring and include it in the Quartz job bean: you might want to read up on some Spring basics before proceeding too much further; this IoC/DI (Inversion of Control/Dependency Injection) is one of the most basic aspects of Spring. getting a handle on it early will save you a lot of effort.
MichaelJ McCabe
Ranch Hand

Joined: Feb 09, 2010
Posts: 49
David Newton wrote:Define the DAO bean in Spring and include it in the Quartz job bean: you might want to read up on some Spring basics before proceeding too much further; this IoC/DI (Inversion of Control/Dependency Injection) is one of the most basic aspects of Spring. getting a handle on it early will save you a lot of effort.


Thank you very much for all your help David. I looked into what you said and got it working by defining the DAO bean and;

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Sweet :) Although I'd avoid naming Spring beans with a capital letter; it's a little confusing. Glad you got it working :)
gopal chandra das
Greenhorn

Joined: Sep 02, 2008
Posts: 1
Its not compiled with version - 2.5.2 ..... getting "The type org.quartz.Job cannot be resolved. It is indirectly referenced from required .class
files" messages in eclipse.

please help me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring with Quartz
 
Similar Threads
How to pass values to spring schedular at run time?
Spring Quartz migration to WAS
Quartz job stoping after some time
no bean named 'crontrigger' is defined
Restrict quartz scheduler to single instance.