Loading beans in spring...

Posted on by Charalampos Chrysikopoulos

We developed an e-shop (a front end and a back end) as an eclipse project. The front end produces its own war and the back end a different one. Both web applications uses the same API and have differences in the GUI. A major difference is that the back end uses scheduling (quartz) and the front end not. The API is configured with spring.

We decided to configure quartz with spring and the job we needed to run with it. The result was, that the front end, using the same configuration as the back end, initialized the quartz framework and enabled its own scheduling. But that was not what we wanted to do.

The solution was simple. At the definition of a spring bean in the configuration there is an attribute in the bean tag named lazy-init. The default value for this attribute is false, and this means that the container will create a bean of that kind at the initialization process. If you give the value true, then the bean will be created only at the time when you request it.

<br /><bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" init="true"><br /> <property name="dataSource" ref="dataSource"><br /> <property name="triggers"><br />  <list><br />   <ref bean="someJobCronTrigger"><br />  </ref><br /> </list><br /></property><br /></property></bean><br />

So, the scheduler initializes in the back end, because we want it to do so, and in the front end it stays only as a bean in the spring configuration.

This entry was posted in configuration, quartz, spring and tagged by Charalampos Chrysikopoulos