Posted By

jcblitz on 09/16/08


Tagged

web MVC application spring Hibernate


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

jcblitz
elCarras
Tyster


web.xml for Spring MVC, hibernate filter, and sitemesh web application


 / Published in: XML
 

Basic web.xml setup for using Spring MVC, Sitemesh, and Hibernate (using hibernate filter for lazy loading)

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app id="BioSafetyWebApp" version="2.4"
  3. xmlns="http://java.sun.com/xml/ns/j2ee"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  6.  
  7. <display-name>Archetype Created Web Application</display-name>
  8.  
  9. <context-param>
  10. <param-name>contextConfigLocation</param-name>
  11. <param-value>
  12. /WEB-INF/yourApplicationNameHere-context.xml
  13. /WEB-INF/yourApplicationNameHere-servlet.xml
  14. /WEB-INF/yourApplicationNameHere-persistence.xml
  15. /WEB-INF/yourApplicationNameHere-security.xml
  16. /WEB-INF/yourApplicationNameHere-service.xml
  17. </param-value>
  18. </context-param>
  19.  
  20. <servlet>
  21. <servlet-name>yourApplicationNameHere</servlet-name>
  22. <servlet-class>
  23. org.springframework.web.servlet.DispatcherServlet
  24. </servlet-class>
  25. <load-on-startup>1</load-on-startup>
  26. </servlet>
  27.  
  28. <servlet-mapping>
  29. <servlet-name>yourApplicationNameHere</servlet-name>
  30. <url-pattern>*.htm</url-pattern>
  31. </servlet-mapping>
  32.  
  33. <listener>
  34. <listener-class>
  35. org.springframework.web.context.ContextLoaderListener
  36. </listener-class>
  37. </listener>
  38.  
  39. <filter>
  40. <filter-name>sitemesh</filter-name>
  41. <filter-class>
  42. com.opensymphony.module.sitemesh.filter.PageFilter
  43. </filter-class>
  44. </filter>
  45.  
  46. <filter-mapping>
  47. <filter-name>sitemesh</filter-name>
  48. <url-pattern>/*</url-pattern>
  49. </filter-mapping>
  50.  
  51. <!-- Allows me to lazy load objects -->
  52. <filter>
  53. <filter-name>hibernateFilter</filter-name>
  54. <filter-class>
  55. org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
  56. </filter-class>
  57. </filter>
  58. <filter-mapping>
  59. <filter-name>hibernateFilter</filter-name>
  60. <url-pattern>/*</url-pattern>
  61. </filter-mapping>
  62.  
  63. <!-- Usually just does a jsp forward to a default action -->
  64. <welcome-file-list>
  65. <welcome-file>index.jsp</welcome-file>
  66. </welcome-file-list>
  67.  
  68. <!-- Commented out during development, it's easier to just see the app server blow up
  69.  
  70. <error-page>
  71. <error-code>404</error-code>
  72. <location>/404.jsp</location>
  73. </error-page>
  74. <error-page>
  75. <exception-type>java.lang.Exception</exception-type>
  76. <location>/error.jsp</location>
  77. </error-page>
  78.  
  79. -->
  80. </web-app>

Report this snippet  

You need to login to post a comment.