Some initial configuration is needed before you can set about defining your bean definitions. This extra setup is not required if you just want scopes singleton and prototype.

In case you are using Servlet 2.4+ web container, then add the following ContextListener to the XML declarations in your web applications 'web.xml' file.

Java Code:
<web-app>
<listener>
<listener-class>org.springframework.web.context.scope.RequestContextListener</listener-
class>
</listener>
</web-app>

In case of older web container (before Servlet 2.4), use a (provided) javax.servlet.Filter implementation in web.xml File.



<web-app>

<filter>
<filter-name>requestContextFilter</filter-name>
<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>requestContextFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

</web-app>
These snippets bind the HTTP request object to the Thread that is servicing that request. This makes beans that are request- and session-scoped available further in applications.