Spring
Hoople can be used to better manage your spring-servlet.xml file. Using Hoople allows you to specify the available bean mappings in easy to manage files that correspond to the controller paths, rather than putting them all in the spring-servlet.xml file.
Add a “spring” tag within the URL XML file. Here is an example file that could be stored as /news/news.form
<?xml version='1.0'?>
<!DOCTYPE url PUBLIC "-//SUNDOG//DTD HOOPLE//EN"
"http://www.sundog.net/hoople/dtd/hoople_1_0.dtd">
<url>
<spring>
<bean class="net.sundog.hoople.example.spring.controller.ExampleController">
<property name="formView" value="index.jsp"/>
<property name="successView" value="thankyou.jsp"/>
</bean>
</spring>
</url>
Within “spring” tag, you specify what you normally would for that bean mapping in Spring with a few modifications.
- You don’t need to specify the nameattribute, because that can be determined by the location of the file.
- You can use relative paths for jsp references and they will be converted to the absolute paths that Spring requires when they are added to the spring-servletxml file
Create a spring-servlet.base.xml file. This is the same as the normal spring-servlet.xml but doesn’t need to include any controller mappings.
Once you have your URL XML file(s) created, add a call to hoople in your Ant build script:
<taskdef name="hoople" classname="net.sundog.hoople.ant.HoopleTask">
<classpath refid="classpath"/>
</taskdef>
<hoople documentRoot="${document.root}">
<include name="**/*.html"/>
<include name="**/*.do"/>
<spring baseFile="${document.root}/WEB-INF/spring-servlet.base.xml"
finalFile="${document.root}/WEB-INF/spring-servlet.xml"/>
</hoople>
When you run your Ant task, you will get a generated standard spring-servlet.xml that contains everything in the spring-servet.base.xml plus all your action mappings.
It is best to not check the generated spring-servlet.xml into your version control system since it will be prone to conflicts as different developers generate it on a regular basis.