Java Reference
In-Depth Information
Listing 6-16.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
<web-app>
<display-name>Spring Batch Webapp</display-name>
<description>A web application that wraps Spring Batch jobs</description>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:launch-context.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
</web-app>
The
web.xml
file exists in the
<project_home>/src/main/webapp/WEB-INF/
directory. With the POM
file updated and the
web.xml
file defined in the correct place, you can generate a war file using the
standard
mvn clean install
.
Now that you have a working war file, let's configure
AutomaticJobRegistrar
to register the jobs on
startup in your JobRegistry. Just as in previous examples,
AutomaticJobRegistrar
is configured to
register all jobs that are listed in the
/jobs/
directory of your classpath. From there, you can use Quartz
as you did earlier in this chapter to launch the job. Listing 6-17 shows
launch-context.xml
configured
with both the previous Quartz configuration and
AutomaticJobRegistrar
.
Listing 6-17.
Updates to
launch-context.xml
...
<bean
class="org.springframework.batch.core.configuration.support.
AutomaticJobRegistrar">
<property name="applicationContextFactories">
<bean
class="org.springframework.batch.core.configuration.support.
ClasspathXmlApplicationContextsFactoryBean">
<property name="resources"
value="classpath*:/jobs/deleteFilesJob.xml" />
</bean>
</property>
<property name="jobLoader">
<bean class="org.springframework.batch.core.configuration.support.
DefaultJobLoader">
<property name="jobRegistry" ref="jobRegistry" />
</bean>
</property>