Spring 3 MVC hello world example
Before you start this Spring 3 MVC tutorial, please refer to this new features in Spring 3 documentation, so that you have a brief idea of what’s new in Spring 3.
In this tutorial, we show you how to develop a Spring 3 MVC hello world example.
Technologies used :
- Spring 3.0.5.RELEASE
- JDK 1.6
- Maven 3
- Eclipse 3.6
1. Project Dependency
In Spring 3 @MVC, declares following dependencies in your Maven pom.xml file.
<properties> <spring.version>3.0.5.RELEASE</spring.version> </properties> <dependencies> <!-- Spring 3 dependencies --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> </dependencies> </project>
2. Controller & Mapping
In Spring 3, annotation is widely adapted in everywhere. The @RequestMapping is available since 2.5, but now enhanced to support REST style URLs in Spring MVC.
package com.mkyong.common.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @Controller @RequestMapping("/welcome") public class HelloController { @RequestMapping(method = RequestMethod.GET) public String printWelcome(ModelMap model) { model.addAttribute("message", "Spring 3 MVC Hello World"); return "hello"; } }
3. JSP Views
A JSP page to display the value.
File : hello.jsp
<html> <body> <h1>Message : ${message}</h1> </body> </html>
4. Spring Configuration
In Spring 3, you still need to enable “auto component scanning” (for controller) and declares “view resolver” manually.
File : mvc-dispatcher-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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="com.mkyong.common.controller" /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix"> <value>/WEB-INF/pages/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean> </beans>
5. Integrate Web application with Spring
Integration is no different if compare with old Spring 2.5.6, just declares Spring “ContextLoaderListener” and “DispatcherServlet“.
File : web.xml
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>Spring MVC Application</display-name> <servlet> <servlet-name>mvc-dispatcher</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>mvc-dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> </web-app>
6. Demo
URL : http://localhost:8080/SpringMVC/welcome

Download Source Code
References
- Spring 3 hello world example
- What new in Spring 3
- Spring 3 MVC and JSR303 @Valid example
- Spring 3 MVC and RSS feed example
- Spring 3 MVC and XML example
- Spring 3 MVC and JSON example
- Spring 3 REST hello world example
- Spring 2.5.6 MVC hello world example
- Spring 2.5.6 MVC hello world annotation example

Decent example but lacking any meaningful Eclipse setup instructions.
I am getting following output:
Message :
But the message i have set in the model object is not displaying in JSP.
please give me suggestion in order to fix the issue.
I just downloaded your source, removed all references to eclipse, loaded into intellij, deployed to Tomcat and it ran the first time.
Now I have a good starting point from which to break this up as I learn how everything is wired together.
Thanks so much.
Thurman
Very good one
Hi ,
Iam using Spring source Tool Suite to execute spring exaxmples.i am trying to execute example with Maven, SPring3 , Hibernate , iam getting
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
this kind of error , i checked all jars are present in Maven Dependencies tab in the build path. Could u please help me out on this.
All jars are presnt in build path(classpath).Don;t know where iam going wrong.
Hi iam using Spring source Tool Suite to execute Spring 3 example ,i tried an example with maven , hibernate spring 3 , all maven dependencies are in the librabries (classpath) related to spring hibernate are thier in classpath.but still iam getting ClassNotFoundException for the DispathcerServlet class. please help me out on this.
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
Hi
One question. How you are setting up the project in eclipse. Can you please share steps for same ? like how you are creating project structure in eclipse?
Thanks
Hi Spring Dude,
Steps i did in Eclipse:
1) Created Dynamic Web application.
2) Copied files from Mkyong tutorial
3) copied spring jars to WEB-INF/lib
4) Run on Server pointing to Tomcat 6
It seems like this option doesn’t have any classpath defined. I am not really sure how to tell it about WEB-INF/lib dir. Any idea if that is possible?
Many Thanks,
Chris
Hi Everyone,
Do get the following problem while deploying the war file built by maven to jetty:
ProjectClassLoader: entry=C:\Users\longinus\.m2\repository\org\springframework\spring-context\3.1.2.RELEASE\spring-context-3.1.2.RELEASE.jar
….
2013-01-31 17:00:46.212:INFO::jetty-6.1.26
2013-01-31 17:00:46.307:WARN::failed org.mortbay.jetty.webapp.WebAppContext@77fddc31{/SpringMVC,D:\JAVA\workspace\SpringMVC\src\main\webapp}: java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextException
2013-01-31 17:00:46.307:WARN::Error starting handlers
java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
at java.lang.Class.getConstructor0(Class.java:2699)
at java.lang.Class.newInstance0(Class.java:326)
at java.lang.Class.newInstance(Class.java:308)
hi …mkyong..i had tried that spring mvc hello world example…while am run the maven and server am getting following error..please helpme …soon
Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:532)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:514)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:133)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4727)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Jan 07, 2013 5:37:26 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Skipped installing application listeners due to previous error(s)
Jan 07, 2013 5:37:26 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
Jan 07, 2013 5:37:26 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/SpringMVC] startup failed due to previous errors
Jan 07, 2013 5:37:26 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Jan 07, 2013 5:37:26 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jan 07, 2013 5:37:26 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 798 ms
Hey,
I know this post is oldish but on my own project. I changed the name of my mvc-dispatcher-servlet.xml to spring-mvc-dispatcher-servlet.xml and placed it in WEB-INF/SpringConf The weird thing with tomcat7 when i publish using eclipse is that the other spring frameworks i used appear to start loading (spring security, and spring hibernate) but the mvc is not loaded because it is looking for WEB-INF/mvc-dispatcher-servlet.xml.
This is kind of confusing. Is this a convention I missed in my readings?
Very useful content.
I am beginner for Spring and Maven and I found this content much useful.
Thanks
Hi,
I am using Netbeans 7.2 and tomcat 7. This is my 5th time trying to get this code run but am always getting this error ” Line 10 in XML document from ServletContext resource [/WEB-INF/dispatcher-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 10; columnNumber: 56; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element ‘context:component-scan’.”
Please help.
Check your xml name space and put proper xsd definition that will help
For the following WARNING and the subsequently resulting HTTP 404 error:
WARNING: No mapping found for HTTP request with URI [/SpringMVC/welcome] in DispatcherServlet with name ‘mvc-dispatcher’
To correct the “No mapping” issue (out of the box for IntelliJ 11.1 w/Tomcat 7.0.26 deploying exploded war), I changed the following line of code in “HelloController.java”:
from:
to:
I still cannot make it work.
I get WARN org.springframework.web.servlet.PageNotFound – No mapping found for HTTP request with URI [/SpringMVC/welcome] in DispatcherServlet with name ‘mvc-dispatcher’
My controller has this:
@RequestMapping(“/SpringMVC/welcome”)
Thanks Natalie
u have to put this url: http://localhost:_your_port_/SpringMVC/welcome
Thank you!
You’ve saved my time with this working simple example I needed!
try to use 3.1.2 instead of 3.0.5
try to use 3.1.2.RELEASE instead of 3.0.5 RELEASE
Dear editor
It would be better to express that, returned string from Controller indetifies jsp page as which view to be used on return.
Thanks for your greata work.
Very Good and Thanx a lot
very good examples.
hi
i get thsi result
Message :
i mean the “Spring 3 MVC Hello World” is not shown
i have no errors
my console is :
1-Aug-2012 3:11:08 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property ‘source’ to ‘org.eclipse.jst.jee.server:cdProject’ did not find a matching property.
1-Aug-2012 3:11:08 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property ‘source’ to ‘org.eclipse.jst.jee.server:student’ did not find a matching property.
1-Aug-2012 3:11:08 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property ‘source’ to ‘org.eclipse.jst.j2ee.server:SpringMVC’ did not find a matching property.
1-Aug-2012 3:11:08 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Java\jdk1.6.0_22\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Java/jre6/bin/client;C:/Java/jre6/bin;C:/Java/jre6/lib/i386;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\QuickTime\QTSystem\;C:\Program Files\Common Files\Acronis\SnapAPI\;C:\Program Files\MATLAB\R2011a\runtime\win32;C:\Program Files\MATLAB\R2011a\bin;C:\Java\jdk1.6.0_22\bin
1-Aug-2012 3:11:08 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
1-Aug-2012 3:11:08 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 347 ms
1-Aug-2012 3:11:08 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
1-Aug-2012 3:11:08 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.20
1-Aug-2012 3:11:08 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
1-Aug-2012 3:11:08 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
1-Aug-2012 3:11:08 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Wed Aug 01 15:11:08 IRDT 2012]; root of context hierarchy
1-Aug-2012 3:11:09 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]
1-Aug-2012 3:11:09 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@13f210f: defining beans [helloController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.web.servlet.view.InternalResourceViewResolver#0]; root of factory hierarchy
1-Aug-2012 3:11:09 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 521 ms
1-Aug-2012 3:11:09 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet ‘mvc-dispatcher’
1-Aug-2012 3:11:09 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet ‘mvc-dispatcher’: initialization started
1-Aug-2012 3:11:09 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace ‘mvc-dispatcher-servlet’: startup date [Wed Aug 01 15:11:09 IRDT 2012]; parent: Root WebApplicationContext
1-Aug-2012 3:11:09 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]
1-Aug-2012 3:11:09 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@55bb93: defining beans [helloController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.web.servlet.view.InternalResourceViewResolver#0]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@13f210f
1-Aug-2012 3:11:09 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/welcome] onto handler ‘helloController’
1-Aug-2012 3:11:09 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/welcome.*] onto handler ‘helloController’
1-Aug-2012 3:11:09 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/welcome/] onto handler ‘helloController’
1-Aug-2012 3:11:09 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet ‘mvc-dispatcher’: initialization completed in 206 ms
1-Aug-2012 3:11:09 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
1-Aug-2012 3:11:09 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
1-Aug-2012 3:11:09 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/21 config=null
1-Aug-2012 3:11:09 PM org.apache.catalina.startup.Catalina start
1.Tomcat did not find a matching property.
2.The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path://
Hi
I am trying to develop small Spring MVC 3 application using spring-framework-3.1.2.RELEASE.zip. I downloaded this release from http://www.springsource.org/download/community. When I included the Spring jar files, my application was not running and I was getting error “Servlet dispatcher not available”. I noticed that spring-framework-3.1.2.RELEASE.zip did not had Spring MVC jar file. I included this spring mvc jar file from lower version say Spring 3.0 then my application started running.
I have noticed the lower version and the higher version spring-3.2.0.M1-dist.zip both have spring mvc jar file then why this jar file is missing in spring-framework-3.1.2.RELEASE.zip which is the current stable version as it GA version. Please clarify.
Thanks
Vijay
Hi Yong,
i am getting following error, even i am using org.springframework.web-3.1.1.RELEASE jar file in my lib folder.
SEVERE: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.NoClassDefFoundError: org/springframework/web/context/ContextCleanupListener
at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:144)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4245)
at org.apache.catalina.core.StandardContext.stop(StandardContext.java:4886)
at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:936)
at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1212)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1382)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:306)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1389)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1653)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1662)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1642)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.springframework.web.context.ContextCleanupListener
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
… 13 more
what will be the cause for it
Hi,
I am new to Spring MVC and I tried your example by downloading the source code. But my compiler complaints of :
“Unbound classpath variable: ‘M2_REPO/aopalliance/aopalliance/1.0/aopalliance-1.0.jar’ in project ‘SpringMVC’”. Can you giude me in the right direction.
Thanks
Hey. Have you solve this issue.? Thanks.
In Eclipse, add “M2_REPO” variable and point it to to your Maven repository.
Can you show step by step for this ? is it Name=M2_REPO , Path = C:\Program Files\Apache Software Foundation\apache-maven-3.0.4 ?
Hello,
I was wondering how would i integrate hibernate 4 with this example project. I am new to spring annotations and would really appreciate some help
Thanks
Andrew
Good Starting for WEB MVC..
I have a question . we have
is able to find the @Controllers and able to handle my request then
what is the use of ?
Raj
in this example one problem is there. for running this one more you need to add and its
name is org.springframework.context-3.0.5.RELEASE.jar. then you can compile code.
otherwise you will get compilation error.
how to hide parameter in url example ..
http://localhost:9090/LifecareEMR/ChiefComplaintsEdit.html?id=8
i want to hide id=8 i am using spring & hibernate MVC form..
plz give me help
In web application request sending two approach
1. get
2. post
if you are sending any data via get request it’s always looks on url.
and via post send data to goes form body scpoe of web application
so you send data via post request.
thanks
J J
Dumb question but… how can I display image or include css file to the jsp file?
For example if my hello.jsp looks like:
Message : ${message}And image.jpg file is in webapp folder.
Where exactly should be image.jpg file in project structure, and is that url (“/SpringMVC/image.jpg”) correct? Because I try to add some jpg and css files in several ways and for now without effect.
My hello.jsp file:
Message : ${message}
Hi,
I have downloaded the above example and imported to my eclipse workspace as a maven project and i didn’t change any thing.I just run that project as RunAs -> Maven Install and after that i copied the war file to the webapps of tomcat and i just started the tomcat.I hit the following URL
http://localhost:8080/SpringMVC/welcome
I am getting the following Exception….
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/apache/el/ExpressionFactoryImpl
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:268)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause
java.lang.NoClassDefFoundError: org/apache/el/ExpressionFactoryImpl
org.apache.jasper.JspCompilationContext.getDerivedPackageName(JspCompilationContext.java:454)
org.apache.jasper.JspCompilationContext.getServletPackageName(JspCompilationContext.java:443)
org.apache.jasper.JspCompilationContext.createOutputDir(JspCompilationContext.java:668)
org.apache.jasper.JspCompilationContext.getOutputDir(JspCompilationContext.java:197)
org.apache.jasper.JspCompilationContext.getClassFileName(JspCompilationContext.java:514)
org.apache.jasper.compiler.Compiler.isOutDated(Compiler.java:453)
org.apache.jasper.compiler.Compiler.isOutDated(Compiler.java:399)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:585)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause
java.lang.ClassNotFoundException: org.apache.el.ExpressionFactoryImpl
java.net.URLClassLoader$1.run(URLClassLoader.java:366)
java.net.URLClassLoader$1.run(URLClassLoader.java:355)
java.security.AccessController.doPrivileged(Native Method)
java.net.URLClassLoader.findClass(URLClassLoader.java:354)
java.lang.ClassLoader.loadClass(ClassLoader.java:423)
java.lang.ClassLoader.loadClass(ClassLoader.java:356)
org.apache.jasper.JspCompilationContext.getDerivedPackageName(JspCompilationContext.java:454)
org.apache.jasper.JspCompilationContext.getServletPackageName(JspCompilationContext.java:443)
org.apache.jasper.JspCompilationContext.createOutputDir(JspCompilationContext.java:668)
org.apache.jasper.JspCompilationContext.getOutputDir(JspCompilationContext.java:197)
org.apache.jasper.JspCompilationContext.getClassFileName(JspCompilationContext.java:514)
org.apache.jasper.compiler.Compiler.isOutDated(Compiler.java:453)
org.apache.jasper.compiler.Compiler.isOutDated(Compiler.java:399)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:585)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
Why i am getting this exception i don’t know.I didn’t modify anything in the code…Can you please tell me the reason…..
Hi Sir,
Thank for this tutorial
I’m working with Tomcat 7.0 , and i deployed the application on Tomcat but when starting the server i’m getting this error ;
…
…
Infos: Server startup in 2846 ms
janv. 26, 2012 12:44:17 PM org.apache.catalina.core.StandardWrapperValve invoke
Grave: Servlet.service() for servlet [jsp] in context with path [] threw exception [java.lang.VerifyError: (class: org/apache/jasper/runtime/JspApplicationContextImpl, method: createELResolver signature: ()Ljavax/el/ELResolver;) Incompatible argument to function] with root cause
java.lang.VerifyError: (class: org/apache/jasper/runtime/JspApplicationContextImpl, method: createELResolver signature: ()Ljavax/el/ELResolver;) Incompatible argument to function
at org.apache.jasper.runtime.JspFactoryImpl.getJspApplicationContext(JspFactoryImpl.java:209)
at org.apache.jsp.index_jsp._jspInit(index_jsp.java:31)
at org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:49)
at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:181)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:370)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:185)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:151)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:269)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Thank you in advance
I got an error
21 Dec, 2011 12:14:46 AM org.springframework.web.servlet.DispatcherServlet noHandlerFound WARNING: No mapping found for HTTP request with URI [/BOL/home] in DispatcherServlet with name ‘mvc-dispatcher’
I have gone wrone somewhere. I just modified your codes at couple of places. I tried your code also directly and got the same error. I posted it here but didt get any reply http://stackoverflow.com/questions/8580428/spring-3-no-mapping-found-for-http-request-beginner
it’s good example.
The HelloController.java need update, as RequestMapping ask for url declared with property style, value=?, for example
@Akhil,
I was getting the same error… this is how I fixed it – hope it helps.
To get rid of the “No mapping found…” error make sure you have a “classes” folder under “WEB-INF” folder and also make sure that this classes folder contains the compiled “.class” file of your java class “HelloController.java”.
If you don’t see any compiled .class file in that folder then you definitely have any error in your project, fix that error and eclipse will compile the class for you.
Also right-click project then select “properties” then select “Java build path” then click on “Source” tab and set the WEB-INF/classes as your Default output folder.
Thanks a lot Rizwan
You save my night :-)
After having thousands of problems with maven (that i finally solved by myself) i had the same problem
Your solution is the wright one
By default, My compiled classes were put in target/classes
Hi, Thanks for the very useful example.I’m facing a problem with it,I have done every thing as you mentioned but only instead of maven I used eclipse with pre-downloaded JAR files.the problem is the the controller is not replacing the message variable with the actual value and showin the message as ${message}!
Can you help me to overcome this issue please?
Hi borzou,
Please put following line on top of your jsp page:
It works =)
i also was try to debug the damn thing..
the example is using a web-app_2_4 schema so it get the false by default.
much appreciated
You said that:
In Spring 3 @MVC, declares following dependencies in your Maven pom.xml file
So, do we need to write anything in POM.xml file or we should keep it blank and everything what you have mentioned above will be added automatically.
And if we need to write then what part we have to add and what part will be added automatically ?
Download the example, and see what inside the pom.xml. At first, learn Maven.