The Web Module

The web module is the module that enables you to write an web application using the spring-annotation almost without XML, to use it you just need to configure the web.xml

Configuring your web.xml

Just add the following lines in your web.xml file:

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath*:applicationContext.xml</param-value>

</context-param>

<context-param>

<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

<servlet>

<servlet-name>dispatcher</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>dispatcher</servlet-name>

<url-pattern>/web/*</url-pattern>

</servlet-mapping>



As you can see, except for the contextConfigLocation, it is a vanilla spring-mvc configuration, after that just follow the instruction of the base module and add the following code to your applicationContext.xml or to your dispatcher-servlet.xml:

add the Spring-Annotation Schema to your spring XML file:

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:sa="http://sannotations.sourceforge.net/context"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd

http://sannotations.sourceforge.net/context http://sannotations.sourceforge.net/context.xsd">



and use the following code:

<import resource="classpath*:applicationContext.xml"/>

<sa:annotation-autoload />

Annotations

After you have configured your web.xml, you just need to use the web annotations in your beans as follows:



@UrlMapping

Configures the URL for this controller, must be used in a class that implements the Controller from the springMVC framework

@UrlMappings

Enables the configuration of more that one URL for the same controller

Examples

Your can look at Example 2 or Example 2 with libs to look how to use the basics of this module.