Welcome to Spring MVC Example. Sometime back in Spring MVC Tutorial, I explained how to create Spring MVC application using Spring Tool Suite. But today, I will be creating a basic hello world spring MVC application using maven and Eclipse.
Spring MVC is based on Model-View-Controller architecture. Below image shows Spring MVC architecture at a high level. DispatcherServlet
is the front controller class to take all requests and start processing them. We have to configure it in web.xml file. It’s job is to pass request to appropriate controller class and send the response back when view pages have rendered the response page. HomeController.java
will be the single controller class in our spring mvc example application. home.jsp
, user.jsp
are the view pages in our spring mvc hello world example application. User.java
will be the only model class we will have in our spring mvc example web application.
Below image shows our Spring MVC example project in Eclipse. Let’s get started and create our project right from the scratch.
Since it’s a web application and we want to use maven for dependencies management, first of all we have to create a dynamic web application and then convert it to a maven project. Below images show how to do this and get our project skeleton structure ready. Right click on the project explorer window and click on “New -> Dynamic Web Project” as shown in below image. Provide name as “spring-mvc-example” in the next popup page, rest of the things should not required to be changed. On next page, provide the source folder as “src/main/java”. You might have to remove “src” folder from the list before adding this. Next is the web module page, provide the context root of application as “spring-mvc-example” and make sure to check “Generate web.xml deployment descriptor” option. Click on Finish and you will have a new Dynamic Web Project in your eclipse project explorer.
We want to use maven for easily manage our spring mvc dependencies. So let’s convert our web project to maven. Right click on the project and select “Configure -> Convert to Maven Project”. Next provide the pom.xml configurations as shown below. Our maven web application project skeleton code is ready. Now we can start making changes to it and create our spring mvc hello world example application.
We need to add spring-web and spring-webmvc dependencies in pom.xml, also add servlet-api, jsp-api and jstl dependencies. Our final pom.xml file will be like below.
<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.journaldev.spring.mvc</groupId>
<artifactId>spring-mvc-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Spring MVC Example</name>
<description>Spring MVC Hello World Example</description>
<!-- Add Spring Web and MVC dependencies -->
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
<finalName>${project.artifactId}</finalName> <!-- added to remove Version from WAR file -->
</build>
</project>
Notice the finalName
configuration in build, so that our WAR file name doesn’t have version details. When the project is build by Eclipse, you will notice all the jars showing up in maven dependencies section.
We have to add Spring MVC framework to our web application, for that we need to configure DispatcherServlet
in web.xml as shown below.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns="https://java.sun.com/xml/ns/javaee" xsi:schemaLocation="https://java.sun.com/xml/ns/javaee https://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>spring-mvc-example</display-name>
<!-- Add Spring MVC DispatcherServlet as front controller -->
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
contextConfigLocation
init-param is used to provide the location of spring bean configuration file.
Next step is to create spring bean configuration file spring-servlet.xml
as shown below.
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="https://www.springframework.org/schema/mvc"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns:beans="https://www.springframework.org/schema/beans"
xmlns:context="https://www.springframework.org/schema/context"
xsi:schemaLocation="https://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd
https://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
https://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing
infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<context:component-scan base-package="com.journaldev.spring" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources
in the /WEB-INF/views directory -->
<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
</beans:beans>
There are three important configurations.
annotation-driven
tells DispatcherServlet to look for Controller classes using @Controller
annotation.context:component-scan
tells DispatcherServlet where to look for controller classes.InternalResourceViewResolver
bean configuration to specify location of view pages and suffix used. Controller class methods return name of the view page and then suffix is added to figure out the view page to use for rendering the response.We have a single controller class to respond for two URIs - “/” for home page and “/user” for user page.
package com.journaldev.spring.controller;
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.journaldev.spring.model.User;
@Controller
public class HomeController {
/**
* Simply selects the home view to render by returning its name.
*/
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
System.out.println("Home Page Requested, locale = " + locale);
Date date = new Date();
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
String formattedDate = dateFormat.format(date);
model.addAttribute("serverTime", formattedDate);
return "home";
}
@RequestMapping(value = "/user", method = RequestMethod.POST)
public String user(@Validated User user, Model model) {
System.out.println("User Page Requested");
model.addAttribute("userName", user.getUserName());
return "user";
}
}
Note that for simplicity, I have not used any logging framework such as log4j.
We have a simple model class with a single variable and it’s getter-setter methods. It’s a simple POJO class.
package com.journaldev.spring.model;
public class User {
private String userName;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}
We have two view pages as defined below. home.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="https://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page session="false"%>
<html>
<head>
<title>Home</title>
</head>
<body>
<h1>Hello world!</h1>
<P>The time on the server is ${serverTime}.</p>
<form action="user" method="post">
<input type="text" name="userName"><br> <input
type="submit" value="Login">
</form>
</body>
</html>
user.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "https://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>User Home Page</title>
</head>
<body>
<h3>Hi ${userName}</h3>
</body>
</html>
Notice that Spring MVC takes care of mapping form variables to model class variables, that’s why we have same variable name in both places. That’s it, our spring mvc example project is ready to de deployed and test.
We can use Eclipse export as WAR file option to deploy it directly to any running tomcat server webapps directory. However you can also use command line to build the project and then copy it into your favourite servlet container deployment directory.
Once the spring mvc project is deployed, we can access the home page at https://localhost:8080/spring-mvc-example/
. Change the tomcat port and context-root accordingly. That’s all for Spring MVC example, I have tried to keep it as simple as possible. But still if you face any issues then please let me know through comments and I will try to help you out. You can download the final spring mvc example project from below link.
Download Spring MVC Example Project
References: Official Page
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.
Thank you Sir. It is works good and it is very useful.
- Younes
org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 121; cvc-elt.1.a: Cannot find the declaration of element ‘beans:beans’. getting above error
- bhavan
Error in here HTTP Status 404 - type Status report message description The requested resource is not available. Apache Tomcat/8.0.36
- Aju
[INFO] ------------------------------------------------------------- [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? [INFO] 1 error [INFO] ------------------------------------------------------------- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] -------------- I get this error while building the maven project. And when I run the project, I get , SEVERE: Servlet.init() for servlet [spring] threw exception org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 7 in XML document from ServletContext resource [/WEB-INF/spring-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 7; columnNumber: 118; cvc-elt.1: Cannot find the declaration of element ‘beans:beans’.
- vishnu
Hi Sir. I get site can’t be reached error. How to change the tomcat port and context root?
- vishnu
Thanks for this tutorial.
- Jack Liu
Thank you. It is useful.
- Nisarg
This is the best spring mvc example.I had tried with many site but nothing work. Thanxs for this example…!
- Pandurang
Oct 17, 2019 12:19:50 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:\Program Files\Java\jdk1.8.0_201\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jdk1.8.0_201/bin/…/jre/bin/server;C:/Program Files/Java/jdk1.8.0_201/bin/…/jre/bin;C:/Program Files/Java/jdk1.8.0_201/bin/…/jre/lib/amd64;C:\Users\lenovlo\AppData\Local\Programs\Python\Python37-32;C:\Program Files\Java\jdk1.8.0_201\bin;C:\Users\lenovlo\AppData\Local\Programs\Python\Python37-32\Scripts\;C:\Users\lenovlo\AppData\Local\Programs\Python\Python37-32\;C:\Program Files\MySQL\MySQL Shell 8.0\bin\;C:\Windows/system32;C:\Users\lenovlo\Desktop;;. Oct 17, 2019 12:19:50 PM org.apache.tomcat.util.digester.SetPropertiesRule begin WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property ‘source’ to ‘org.eclipse.jst.j2ee.server:add’ did not find a matching property. Oct 17, 2019 12:19:50 PM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler [“http-bio-8080”] Oct 17, 2019 12:19:50 PM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler [“ajp-bio-8009”] Oct 17, 2019 12:19:50 PM org.apache.catalina.startup.Catalina load INFO: Initialization processed in 774 ms Oct 17, 2019 12:19:50 PM org.apache.catalina.core.StandardService startInternal INFO: Starting service Catalina Oct 17, 2019 12:19:50 PM org.apache.catalina.core.StandardEngine startInternal INFO: Starting Servlet Engine: Apache Tomcat/7.0.47 Oct 17, 2019 12:19:51 PM org.apache.catalina.util.SessionIdGenerator createSecureRandom INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [165] milliseconds. Oct 17, 2019 12:19:51 PM org.apache.catalina.loader.WebappClassLoader validateJarFile INFO: validateJarFile(C:\Users\lenovlo\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp6\wtpwebapps\add\WEB-INF\lib\servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class Oct 17, 2019 12:19:52 PM org.apache.catalina.core.ApplicationContext log INFO: No Spring WebApplicationInitializer types detected on classpath Oct 17, 2019 12:19:52 PM org.apache.catalina.core.ApplicationContext log INFO: Initializing Spring FrameworkServlet ‘adds’ Oct 17, 2019 12:19:52 PM org.springframework.web.servlet.DispatcherServlet initServletBean INFO: FrameworkServlet ‘adds’: initialization started Oct 17, 2019 12:19:53 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh INFO: Refreshing WebApplicationContext for namespace ‘adds-servlet’: startup date [Thu Oct 17 12:19:53 PDT 2019]; root of context hierarchy Oct 17, 2019 12:19:53 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/adds-servlet.xml] Oct 17, 2019 12:19:53 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod INFO: Mapped “{[/add.do]}” onto public void add.addcontroller.add(add.HttpServlatRequest,add.HttpServlatResponse) Oct 17, 2019 12:19:53 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache INFO: Looking for @ControllerAdvice: WebApplicationContext for namespace ‘adds-servlet’: startup date [Thu Oct 17 12:19:53 PDT 2019]; root of context hierarchy Oct 17, 2019 12:19:54 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache INFO: Looking for @ControllerAdvice: WebApplicationContext for namespace ‘adds-servlet’: startup date [Thu Oct 17 12:19:53 PDT 2019]; root of context hierarchy Oct 17, 2019 12:19:54 PM org.springframework.web.servlet.DispatcherServlet initServletBean INFO: FrameworkServlet ‘adds’: initialization completed in 1174 ms Oct 17, 2019 12:19:54 PM org.apache.coyote.AbstractProtocol start INFO: Starting ProtocolHandler [“http-bio-8080”] Oct 17, 2019 12:19:54 PM org.apache.coyote.AbstractProtocol start INFO: Starting ProtocolHandler [“ajp-bio-8009”] Oct 17, 2019 12:19:54 PM org.apache.catalina.startup.Catalina start INFO: Server startup in 3656 ms
- riya
Apr 17, 2019 12:42:38 AM 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:\Program Files (x86)\Java\jre1.8.0_51\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files (x86)/Java/jre1.8.0_51/bin/client;C:/Program Files (x86)/Java/jre1.8.0_51/bin;C:/Program Files (x86)/Java/jre1.8.0_51/lib/i386;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Java\jdk1.7.0\bin;C:\Program Files (x86)\Skype\Phone\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\MySQL\MySQL Utilities 1.6\;C:\Program Files (x86)\Windows Live\Shared;F:\Setup\eclipse_new;;. Apr 17, 2019 12:42:38 AM org.apache.tomcat.util.digester.SetPropertiesRule begin WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property ‘source’ to ‘org.eclipse.jst.jee.server:spring-web-example’ did not find a matching property. Apr 17, 2019 12:42:38 AM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler [“http-bio-8080”] Apr 17, 2019 12:42:38 AM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler [“ajp-bio-8009”] Apr 17, 2019 12:42:38 AM org.apache.catalina.startup.Catalina load INFO: Initialization processed in 1301 ms Apr 17, 2019 12:42:38 AM org.apache.catalina.core.StandardService startInternal INFO: Starting service Catalina Apr 17, 2019 12:42:38 AM org.apache.catalina.core.StandardEngine startInternal INFO: Starting Servlet Engine: Apache Tomcat/7.0.37 Apr 17, 2019 12:42:44 AM org.apache.catalina.core.ApplicationContext log INFO: No Spring WebApplicationInitializer types detected on classpath Apr 17, 2019 12:42:44 AM org.apache.catalina.util.SessionIdGenerator createSecureRandom INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [299] milliseconds. Apr 17, 2019 12:42:44 AM org.apache.catalina.core.ApplicationContext log INFO: Marking servlet spring as unavailable Apr 17, 2019 12:42:44 AM org.apache.catalina.core.StandardContext loadOnStartup SEVERE: Servlet /spring-web-example threw load() exception java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1713) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558) at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:527) at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:509) at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:137) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5033) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5317) 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.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Apr 17, 2019 12:42:44 AM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory F:\Setup\eclipse_new\tomcat\apache-tomcat-7.0.37\webapps\docs Apr 17, 2019 12:42:44 AM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory F:\Setup\eclipse_new\tomcat\apache-tomcat-7.0.37\webapps\examples Apr 17, 2019 12:42:44 AM org.apache.catalina.core.ApplicationContext log INFO: ContextListener: contextInitialized() Apr 17, 2019 12:42:44 AM org.apache.catalina.core.ApplicationContext log INFO: SessionListener: contextInitialized() Apr 17, 2019 12:42:44 AM org.apache.catalina.core.ApplicationContext log INFO: ContextListener: attributeAdded(‘org.apache.jasper.compiler.TldLocationsCache’, ‘org.apache.jasper.compiler.TldLocationsCache@13f5d87’) Apr 17, 2019 12:42:44 AM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory F:\Setup\eclipse_new\tomcat\apache-tomcat-7.0.37\webapps\host-manager Apr 17, 2019 12:42:45 AM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory F:\Setup\eclipse_new\tomcat\apache-tomcat-7.0.37\webapps\manager Apr 17, 2019 12:42:45 AM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory F:\Setup\eclipse_new\tomcat\apache-tomcat-7.0.37\webapps\ROOT Apr 17, 2019 12:42:45 AM org.apache.coyote.AbstractProtocol start INFO: Starting ProtocolHandler [“http-bio-8080”] Apr 17, 2019 12:42:45 AM org.apache.coyote.AbstractProtocol start INFO: Starting ProtocolHandler [“ajp-bio-8009”] Apr 17, 2019 12:42:45 AM org.apache.catalina.startup.Catalina start INFO: Server startup in 6656 ms Apr 17, 2019 12:46:55 AM org.apache.catalina.loader.WebappClassLoader modified SEVERE: Resource ‘/WEB-INF/lib/spring-context-4.3.9.RELEASE.jar’ is missing Apr 17, 2019 12:46:55 AM org.apache.catalina.core.StandardContext reload INFO: Reloading Context with name [/spring-web-example] has started Apr 17, 2019 12:47:00 AM org.apache.catalina.core.ApplicationContext log INFO: No Spring WebApplicationInitializer types detected on classpath Apr 17, 2019 12:47:00 AM org.apache.catalina.core.ApplicationContext log INFO: Initializing Spring FrameworkServlet ‘spring’ Apr 17, 2019 12:47:00 AM org.springframework.web.servlet.DispatcherServlet initServletBean INFO: FrameworkServlet ‘spring’: initialization started Apr 17, 2019 12:47:00 AM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh INFO: Refreshing WebApplicationContext for namespace ‘spring-servlet’: startup date [Wed Apr 17 00:47:00 IST 2019]; root of context hierarchy Apr 17, 2019 12:47:00 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-servlet.xml] Apr 17, 2019 12:47:01 AM org.apache.catalina.core.ApplicationContext log SEVERE: StandardWrapper.Throwable java.lang.IncompatibleClassChangeError: class org.springframework.core.type.classreading.ClassMetadataReadingVisitor has interface org.springframework.asm.ClassVisitor as super class at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2888) at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1172) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2888) at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1172) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558) at org.springframework.core.type.classreading.SimpleMetadataReader.(SimpleMetadataReader.java:63) at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:98) at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:102) at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:93) at org.springframework.context.annotation.ConfigurationClassUtils.checkConfigurationClassCandidate(ConfigurationClassUtils.java:69) at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:216) at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:178) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:617) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:446) at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631) at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588) at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645) at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508) at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449) at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133) at javax.servlet.GenericServlet.init(GenericServlet.java:160) at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5033) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5317) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3926) at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:426) at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1345) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1530) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1519) at java.lang.Thread.run(Unknown Source) Apr 17, 2019 12:47:01 AM org.apache.catalina.core.StandardContext loadOnStartup SEVERE: Servlet /spring-web-example threw load() exception java.lang.IncompatibleClassChangeError: class org.springframework.core.type.classreading.ClassMetadataReadingVisitor has interface org.springframework.asm.ClassVisitor as super class at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2888) at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1172) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2888) at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1172) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558) at org.springframework.core.type.classreading.SimpleMetadataReader.(SimpleMetadataReader.java:63) at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:98) at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:102) at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:93) at org.springframework.context.annotation.ConfigurationClassUtils.checkConfigurationClassCandidate(ConfigurationClassUtils.java:69) at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:216) at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:178) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:617) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:446) at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631) at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588) at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645) at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508) at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449) at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133) at javax.servlet.GenericServlet.init(GenericServlet.java:160) at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5033) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5317) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3926) at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:426) at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1345) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1530) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1519) at java.lang.Thread.run(Unknown Source) Apr 17, 2019 12:47:01 AM org.apache.catalina.core.StandardContext reload INFO: Reloading Context with name [/spring-web-example] is completed Apr 17, 2019 12:54:21 AM org.apache.catalina.loader.WebappClassLoader modified SEVERE: Resource ‘/WEB-INF/lib/commons-logging-1.2.jar’ is missing Apr 17, 2019 12:54:21 AM org.apache.catalina.core.StandardContext reload INFO: Reloading Context with name [/spring-web-example] has started Apr 17, 2019 12:54:23 AM org.apache.catalina.core.ApplicationContext log INFO: Marking servlet spring as unavailable Apr 17, 2019 12:54:24 AM org.apache.catalina.core.StandardContext loadOnStartup SEVERE: Servlet /spring-web-example threw load() exception java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1713) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558) at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:527) at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:509) at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:137) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5033) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5317) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3926) at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:426) at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1345) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1530) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1519) at java.lang.Thread.run(Unknown Source) Apr 17, 2019 12:54:24 AM org.apache.catalina.core.StandardContext reload INFO: Reloading Context with name [/spring-web-example] is completed Apr 17, 2019 12:56:14 AM org.apache.catalina.loader.WebappClassLoader modified INFO: Additional JARs have been added Apr 17, 2019 12:56:14 AM org.apache.catalina.core.StandardContext reload INFO: Reloading Context with name [/spring-web-example] has started Apr 17, 2019 12:56:18 AM org.apache.catalina.core.ApplicationContext log INFO: No Spring WebApplicationInitializer types detected on classpath Apr 17, 2019 12:56:18 AM org.apache.catalina.core.ApplicationContext log INFO: Initializing Spring FrameworkServlet ‘spring’ Apr 17, 2019 12:56:18 AM org.springframework.web.servlet.DispatcherServlet initServletBean INFO: FrameworkServlet ‘spring’: initialization started Apr 17, 2019 12:56:19 AM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh INFO: Refreshing WebApplicationContext for namespace ‘spring-servlet’: startup date [Wed Apr 17 00:56:19 IST 2019]; root of context hierarchy Apr 17, 2019 12:56:19 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-servlet.xml] Apr 17, 2019 12:56:21 AM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache INFO: Looking for @ControllerAdvice: WebApplicationContext for namespace ‘spring-servlet’: startup date [Wed Apr 17 00:56:19 IST 2019]; root of context hierarchy Apr 17, 2019 12:56:21 AM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache INFO: Looking for @ControllerAdvice: WebApplicationContext for namespace ‘spring-servlet’: startup date [Wed Apr 17 00:56:19 IST 2019]; root of context hierarchy Apr 17, 2019 12:56:22 AM org.springframework.web.servlet.DispatcherServlet initServletBean INFO: FrameworkServlet ‘spring’: initialization completed in 3113 ms Apr 17, 2019 12:56:22 AM org.apache.catalina.core.StandardContext reload INFO: Reloading Context with name [/spring-web-example] is completed
- Surabhi agarwal