Spring MVC Hello World
Below are needed to run Spring 3 MVC Hello World:
- Eclipse 3.0 or above (Download eclipse from http://www.eclipse.org/downloads/ site)
- JDK 1.6 or above (Download from here: http://www.oracle.com/technetwork/java/javase/downloads/index.html)
- Tomcat 6 or above (Please follow link to install and configure tomcat in eclipse:Configure and Run Tomcat server in eclipse
- Spring jars which is already included in project for download in the bottom
- Spring is very popular framework many companies are adopting it to develop their application. Below is simple spring 3 MVC application to show Hello World.
After all set up and configuration you will see below screen:
- Create dynamic web project in eclipse name: SpringMVCProject (Please use this link if you are not familiar how to create dynamic project in eclipse: Create Dynamic Web Project Eclipse)
- Once you created dynamic web project in eclipse it should look similar to below
- Please copy below jars in lib folder (You could download project from the bottom it contains everything which is need for the project otherwise you could visit: http://projects.spring.io/spring-framework/ to download all jars)
- Please copy below XML into your web.xml file
- Now create file name: dispatcher-servlet.xml inside WEB-INF folder and copy and paste below content
- Create package name com.controller inside src folder
- Create class name: SpringMVCController.java and copy paste below content in it
- Create jsp folder inside WEB-INF folder
- Create jsp file name: helloWorld.jsp and copy paste below content in it
- You’re done. Final directory structure should be same as below:
- Now it’s time to run this set up in tomcat server. If you haven’t done tomcat set up in eclipse yet please use this link:Configure and Run Tomcat server in eclipse. Now right click project –>Run As –> Run on server. Below is reference:
- Finally you should see below Hello World Message.
- You could also directly execute it from link: http://localhost:7001/SpringMVCProject/helloWorld.web because we have request mapping method = RequestMethod.GET in controller.
- If you want please download above project from below download file.
Note: If you download project code from below and import in your eclipse could see some exception, if you are using different version of JDK, ECLIPSE and Web server. Please use below link to sort out any issues:
- Target runtime Apache Tomcat is not defined
- Unbound Classpath container
- Java Compiler Level not match Java Project facet
Download Project: SpringMVCProject