• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Spring with Quartz

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the misspelling of "property" a typo?
 
MichaelJ McCabe
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you execute your application ? How do your read the context file ?
 
MichaelJ McCabe
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the question was more "How are you initializing Spring?"
 
MichaelJ McCabe
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Inject the DAO directly into your Quartz job--that's what Spring is for; why convolute things?
 
MichaelJ McCabe
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sweet :) Although I'd avoid naming Spring beans with a capital letter; it's a little confusing. Glad you got it working :)
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic