Java Reference
In-Depth Information
2. Add the required Spring web-related dependencies to your POM file.
3. Create web.xml in a new directory <project_home>/src/main/webapp/WEB-INF
with ContextLoaderListener to bootstrap Spring.
4. Configure AutomaticJobRegistrar to register the jobs with the JobRegistry.
You start by updating the POM file. In order for Spring to be bootstrapped in a servlet container like
Tomcat, you need to add the Spring framework's web dependencies. Listing 6-14 shows how to
configure the additional dependencies required for this job including Spring's web module, SLF4J, and
Listing 6-14. Additional Dependencies for pom.xml
Instead of creating a jar file for you to execute independently, you want to create a war file that you
can deploy to Tomcat. To do this, you need to update the packaging in your POM file from jar to war.
You also replace the reference to maven-jar-plugin with maven-war-plugin . Listing 6-15 shows how to
configure the POM file so your application is packaged correctly.
Listing 6-15. Revised pom.xml
As Listing 6-15 shows, configuring Maven to generate your war file is very easy. Unfortunately, the
changes to the pom.xml file won't work until you create a web.xml file and put it in the correct place. For
web.xml , you configure a single listener, Spring's
org.springframework.web.context.ContextLoaderListener . It bootstraps Spring as well as the
JobRegistry for you. Listing 6-16 shows the web.xml file.
Search WWH ::

Custom Search