HelloWorld Demo Spring MVC 3.0 Eclipse

Demo/Example to Basics of Spring MVC 3.0 with Eclipse. And Let me tell you configuring Spring MVC with eclipse is very simple. It’s good when you get a chance to compare more technology over their features, Simple example with Spring MVC 3.0 with eclipse. Before starting ahead I would suggest first prepare yourself with related resources such as jar, project structure with eclipse.

Step: 1

required-jars-for-spring-mvc-3

required-jars-for-spring-mvc-3

Step: 2
It is good if you have allocated the above jars. Now lets start with Eclipse to add new ‘Dynamic Web Project’.

Step-1-Create-New-Project-Spring-MVC-3

Step-1-Create-New-Project-Spring-MVC-3

Step: 3
Now, Once you are ready with new dynamic web project. Here is the time to add jar files.

required-jars-for-spring-mvc-3

required-jars-for-spring-mvc-3

Step: 4
Now time to create web.xml file

Step-4-web-xml-Spring-MVC-3

Step-4-web-xml-Spring-MVC-3

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	id="WebApp_ID" version="2.5">
	<display-name>Spring3MVC</display-name>
	<welcome-file-list>
		<welcome-file>home.jsp</welcome-file>
	</welcome-file-list>

	<servlet>
		<servlet-name>spring</servlet-name>
		<servlet-class>
			org.springframework.web.servlet.DispatcherServlet
		</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>spring</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>
</web-app>

Step 5

Step-4-web-xml-Spring-MVC-3

Step-4-web-xml-Spring-MVC-3

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd


http://www.springframework.org/schema/context

		http://www.springframework.org/schema/context/spring-context-3.0.xsd">

	<context:component-scan
		base-package="web.controller" />

	<bean id="viewResolver"
		class="org.springframework.web.servlet.view.UrlBasedViewResolver">
		<property name="viewClass"
			value="org.springframework.web.servlet.view.JstlView" />
		<property name="prefix" value="/WEB-INF/jsp/" />
		<property name="suffix" value=".jsp" />
	</bean>
</beans>

Step 6
Now, You are very well configured Spring MVC 3.0 application. Now point comes have a closer look at ‘spring-servlet.xml’

<context:component-scan
		base-package="web.controller" />

This is basically Spring MVC 3.0 Controller where we really don’t have to depend on XML configuration and we will see a great feature i.e. ‘annotation’ .

Let’s first add a HomeController( controller ) into project and add few action with annotation.

Step-6-HomeController-Spring-MVC-3

Step-6-HomeController-Spring-MVC-3

Step 7
Once you are done with adding the above controller you are almost there to run the project. But Wait, You need to add the following JSP’s as shown into the following screen.

Step-7-JSP-Spring-MVC-3

Step-7-JSP-Spring-MVC-3

Once you are done with this final step; you need to do right click into project node and do

Step-8-RUN-Project-Spring-MVC-3

Step-8-RUN-Project-Spring-MVC-3

Good luck!!!

One thought on “HelloWorld Demo Spring MVC 3.0 Eclipse

  1. Thanks, it helped me a lot. can you post some examples based on session and jdbc connectivity. I am new to spring mvc n working on version 3.0

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>