title: spring Bean creation exception Error creating bean with name
body: <p>Hello all i am new to Spring please solve my problem i am getting bean creation exception here is my code(i created these in dynamic web project) i am trying to do a simple Springmvc project.</p>
  
  <p>file name:  login.Jsp </p>
  
  <pre><code>&lt;form action="login.do" method="post"&gt;
  username&lt;input type="text" name="username"/&gt;
  password&lt;input type="password" name="password"/&gt;
  &lt;input type="submit" value="login"/&gt;
  &lt;/form&gt;   
  </code></pre>
  
  <p>file name : web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"&gt;
  
    &lt;servlet&gt;
    &lt;servlet-name&gt;loginapp&lt;/servlet-name&gt;
    &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
    &lt;servlet-name&gt;loginapp&lt;/servlet-name&gt;
    &lt;url-pattern&gt;*.do&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>file name:loginapp-servlet.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"&gt;
  &lt;beans&gt;
          &lt;bean id="id1" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"&gt;
            &lt;property name="mappings"&gt;
               &lt;props&gt;
                   &lt;prop key="login.do"&gt;id2&lt;/prop&gt;
  
          &lt;/props&gt;
          &lt;/property&gt;
          &lt;/bean&gt;
          &lt;bean id="id2" class="logincontroller"/&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>file name : logincontroller.java</p>
  
  <pre><code>package springmvc;
  
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import org.springframework.web.servlet.ModelAndView;
  import org.springframework.web.servlet.mvc.Controller;
  
  public class logincontroller implements Controller {
  
      @Override
      public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
  
          String username = request.getParameter("username");
          String password = request.getParameter("password");
          loginaction action = new loginaction();
          String result = action.verifyuser(username,password);
          if(result.equals("success"))
          return new ModelAndView("success.jsp");
          else
              return new ModelAndView("failure.jsp");
  
  
      }
  
  }
  </code></pre>
  
  <p>filename : success.jsp</p>
  
  <pre><code>&lt;% out.println("login success");%&gt;
  </code></pre>
  
  <p>file name: failure.jsp</p>
  
  <pre><code>&lt;% out.println("failed");%&gt;
  </code></pre>
  
  <p>after i run login.jsp and typing username as "admin" password as "admin" i am getting this error</p>
  
  <pre><code>HTTP Status 500 - Servlet.init() for servlet loginapp threw exception
  
  
  type Exception report
  
  message Servlet.init() for servlet loginapp threw exception
  
  description The server encountered an internal error that prevented it from fulfilling this request.
  
  exception
  javax.servlet.ServletException: Servlet.init() for servlet loginapp threw exception
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
      org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
      org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784)
      org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
      org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802)
      org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1410)
      org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
      java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      java.lang.Thread.run(Unknown Source)
  
  
  root cause
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'id1' defined in ServletContext resource [/WEB-INF/loginapp-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [logincontroller] for bean with name 'id2' defined in ServletContext resource [/WEB-INF/loginapp-servlet.xml]; nested exception is java.lang.ClassNotFoundException: logincontroller
  Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [logincontroller] for bean with name 'id2' defined in ServletContext resource [/WEB-INF/loginapp-servlet.xml]; nested exception is java.lang.ClassNotFoundException: logincontroller
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
      org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
      org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
      org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
      org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
      org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
      org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
      org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
      org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672)
      org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543)
      org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484)
      org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
      javax.servlet.GenericServlet.init(GenericServlet.java:158)
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
      org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
      org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784)
      org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
      org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802)
      org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1410)
      org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
      java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      java.lang.Thread.run(Unknown Source)
  
  
  root cause
  org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [logincontroller] for bean with name 'id2' defined in ServletContext resource [/WEB-INF/loginapp-servlet.xml]; nested exception is java.lang.ClassNotFoundException: logincontroller
      org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1327)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:594)
      org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1396)
      org.springframework.beans.factory.support.AbstractBeanFactory.isSingleton(AbstractBeanFactory.java:422)
      org.springframework.context.support.AbstractApplicationContext.isSingleton(AbstractApplicationContext.java:1002)
      org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(AbstractUrlHandlerMapping.java:286)
      org.springframework.web.servlet.handler.SimpleUrlHandlerMapping.registerHandlers(SimpleUrlHandlerMapping.java:129)
      org.springframework.web.servlet.handler.SimpleUrlHandlerMapping.initApplicationContext(SimpleUrlHandlerMapping.java:104)
      org.springframework.context.support.ApplicationObjectSupport.initApplicationContext(ApplicationObjectSupport.java:120)
      org.springframework.web.context.support.WebApplicationObjectSupport.initApplicationContext(WebApplicationObjectSupport.java:73)
      org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:74)
      org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:119)
      org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:94)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:407)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1545)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
      org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
      org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
      org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
      org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
      org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
      org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
      org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
      org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672)
      org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543)
      org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484)
      org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
      javax.servlet.GenericServlet.init(GenericServlet.java:158)
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
      org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
      org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784)
      org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
      org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802)
      org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1410)
      org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
      java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      java.lang.Thread.run(Unknown Source)
  
  
  root cause
  java.lang.ClassNotFoundException: logincontroller
      org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)
      org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
      org.springframework.util.ClassUtils.forName(ClassUtils.java:247)
      org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)
      org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1348)
      org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1319)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:594)
      org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1396)
      org.springframework.beans.factory.support.AbstractBeanFactory.isSingleton(AbstractBeanFactory.java:422)
      org.springframework.context.support.AbstractApplicationContext.isSingleton(AbstractApplicationContext.java:1002)
      org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(AbstractUrlHandlerMapping.java:286)
      org.springframework.web.servlet.handler.SimpleUrlHandlerMapping.registerHandlers(SimpleUrlHandlerMapping.java:129)
      org.springframework.web.servlet.handler.SimpleUrlHandlerMapping.initApplicationContext(SimpleUrlHandlerMapping.java:104)
      org.springframework.context.support.ApplicationObjectSupport.initApplicationContext(ApplicationObjectSupport.java:120)
      org.springframework.web.context.support.WebApplicationObjectSupport.initApplicationContext(WebApplicationObjectSupport.java:73)
      org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:74)
      org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:119)
      org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:94)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:407)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1545)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
      org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
      org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
      org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
      org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
      org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
      org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
      org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
      org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672)
      org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543)
      org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484)
      org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
      javax.servlet.GenericServlet.init(GenericServlet.java:158)
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
      org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
      org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784)
      org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
      org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802)
      org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1410)
      org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
      java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      java.lang.Thread.run(Unknown Source)
  
  
  note The full stack trace of the root cause is available in the Pivotal tc Runtime 3.2.2.RELEASE/8.5.6.B.RELEASE logs.
  
  --------------------------------------------------------------------------------
  
  Pivotal tc Runtime 3.2.2.RELEASE/8.5.6.B.RELEASE
  </code></pre>
  
  <p>Here are the jar files i copied in lib folder :</p>
  
  <pre><code>commons-logging-1.2.jar
  spring-aop-4.0.4.RELEASE.jar
  spring-aop-4.0.4.RELEASE-javadoc.jar
  spring-aop-4.0.4.RELEASE-sources.jar
  spring-aspects-4.0.4.RELEASE.jar
  spring-aspects-4.0.4.RELEASE-javadoc.jar
  spring-aspects-4.0.4.RELEASE-sources.jar
  spring-beans-4.0.4.RELEASE.jar
  spring-beans-4.0.4.RELEASE-javadoc.jar
  spring-beans-4.0.4.RELEASE-sources.jar
  spring-build-src-4.0.4.RELEASE.jar
  spring-context-4.0.4.RELEASE.jar
  spring-context-4.0.4.RELEASE-javadoc.jar
  spring-context-4.0.4.RELEASE-sources.jar
  spring-context-support-4.0.4.RELEASE.jar
  spring-context-support-4.0.4.RELEASE-javadoc.jar
  spring-context-support-4.0.4.RELEASE-sources.jar
  spring-core-4.0.4.RELEASE.jar
  spring-core-4.0.4.RELEASE-javadoc.jar
  spring-core-4.0.4.RELEASE-sources.jar
  spring-expression-4.0.4.RELEASE.jar
  spring-expression-4.0.4.RELEASE-javadoc.jar
  spring-expression-4.0.4.RELEASE-sources.jar
  spring-framework-bom-4.0.4.RELEASE.jar
  spring-framework-bom-4.0.4.RELEASE-javadoc.jar
  spring-framework-bom-4.0.4.RELEASE-sources.jar
  spring-instrument-4.0.4.RELEASE.jar
  spring-instrument-4.0.4.RELEASE-javadoc.jar
  spring-instrument-4.0.4.RELEASE-sources.jar
  spring-instrument-tomcat-4.0.4.RELEASE.jar
  spring-instrument-tomcat-4.0.4.RELEASE-javadoc.jar
  spring-instrument-tomcat-4.0.4.RELEASE-sources.jar
  spring-jdbc-4.0.4.RELEASE.jar
  spring-jdbc-4.0.4.RELEASE-javadoc.jar
  spring-jdbc-4.0.4.RELEASE-sources.jar
  spring-jms-4.0.4.RELEASE.jar
  spring-jms-4.0.4.RELEASE-javadoc.jar
  spring-jms-4.0.4.RELEASE-sources.jar
  spring-messaging-4.0.4.RELEASE.jar
  spring-messaging-4.0.4.RELEASE-javadoc.jar
  spring-messaging-4.0.4.RELEASE-sources.jar
  spring-orm-4.0.4.RELEASE.jar
  spring-orm-4.0.4.RELEASE-javadoc.jar
  spring-orm-4.0.4.RELEASE-sources.jar
  spring-oxm-4.0.4.RELEASE.jar
  spring-oxm-4.0.4.RELEASE-javadoc.jar
  spring-oxm-4.0.4.RELEASE-sources.jar
  spring-test-4.0.4.RELEASE.jar
  spring-test-4.0.4.RELEASE-javadoc.jar
  spring-test-4.0.4.RELEASE-sources.jar
  spring-tx-4.0.4.RELEASE.jar
  spring-tx-4.0.4.RELEASE-javadoc.jar
  spring-tx-4.0.4.RELEASE-sources.jar
  spring-web-4.0.4.RELEASE.jar
  spring-web-4.0.4.RELEASE-javadoc.jar
  spring-web-4.0.4.RELEASE-sources.jar
  spring-webmvc-4.0.4.RELEASE.jar
  spring-webmvc-4.0.4.RELEASE-javadoc.jar
  spring-webmvc-4.0.4.RELEASE-sources.jar
  spring-webmvc-portlet-4.0.4.RELEASE.jar
  spring-webmvc-portlet-4.0.4.RELEASE-javadoc.jar
  spring-webmvc-portlet-4.0.4.RELEASE-sources.jar
  spring-websocket-4.0.4.RELEASE.jar
  spring-websocket-4.0.4.RELEASE-javadoc.jar
  spring-websocket-4.0.4.RELEASE-sources.jar
  </code></pre>