Skip to end of metadata
Go to start of metadata

This document provides an abbreviated summary for how to quickly setup Spring MVC in a web app. It assumes that the reader has done it before and is just looking for a fast check-list when doing it again. This procedure will get you started fast and enable you to perform a quick acid-test to make sure things are setup properly.

Import Spring libraries

You'll need at least the following Spring libraries in your WEB-INF/lib folder:

  • commons-logging.jar (Apache Commons Logging - required by Spring)
  • glassfish.jstl_1.2.0.1.jar (or whatever JSTL implementation you want to use)
  • org.springframework.asm-X.X.X.RELEASE.jar
  • org.springframework.beans-X.X.X.RELEASE.jar
  • org.springframework.context-X.X.X.RELEASE.jar
  • org.springframework.context.support-3.0.5.RELEASE.jar
  • org.springframework.core-X.X.X.RELEASE.jar
  • org.springframework.expression-X.X.X.RELEASE.jar
  • org.springframework.web.servlet-X.X.X.RELEASE.jar
  • org.springframework.web-X.X.X.RELEASE.jar

Edit web.xml

Add the following stanza to your web.xml file:

Create a HelloWorld.jsp view page

Create a 'pages' directory inside of WEB-INF and then create a HelloWorld.jsp file inside of that. You can use the following for the contents of the JSP file:

Create app-servlet.xml file

Since our DispatcherServlet is named 'app' in the web.xml file, we need to create a corresponding app-servlet.xml file in the WEB-INF directory. Following are the minimum contents for the file that you should need. Keep in mind that you should change the component-scan base-package where your controllers should reside if it differs on your system.

Create HelloWorldController

You'll need a controller. Here's a very simple HelloWorldController you can use:

Test it

Now deploy the application and hit the URL context /hello-world. This should fire the controller, which will print a statement to the System.out. Also, your view JSP should be returned.

That's it! Now you know you've got Spring Web MVC setup and working; a good starting point.

Labels:
spring spring Delete
mvc mvc Delete
java java Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.