title: org.springframework.beans.factory.BeanCreationException: as well as org.springframework.beans.BeanInstantiationException
body: <p>I tried to do login and some database manipulations(insert,delete) in spring and also help with jsp.I am totally new to spring.I am getting the following error like bean creation exception.I have defined dvd as servlet name in web.xml. So my dvd_servlet.xml file is as like below</p>
  
  <pre><code>&lt;beans.................&gt;
  &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/&gt;
      &lt;property name="prefix" value="/"/&gt;
      &lt;property name="suffix" value=".jsp"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource"&gt;
          &lt;property name="driverClassName" value="com.mysql.jdbc.Driver"/&gt;
          &lt;property name="url" value="jdbc:mysql://localhost:3306/DVD"/&gt;
          &lt;property name="username" value="root"/&gt;
          &lt;property name="password" value="root"/&gt;
  &lt;/bean&gt;
  
  &lt;bean name="DvdController" class="DvdController" &gt;
      &lt;property name="dataSource" ref="dataSource"/&gt;
  &lt;/bean&gt;
  &lt;bean name="LoginController" class="LoginController" &gt;
      &lt;property name="dataSource" ref="dataSource"/&gt;
  &lt;/bean&gt;
  &lt;bean name="AccountCreationController" class="AccountCreationController" &gt;
      &lt;property name="dataSource" ref="dataSource"/&gt;
  &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>my LoginController is like</p>
  
  <pre><code>public class LoginController implements Controller   {
  
       int check;
      private DataSource dataSource;
       public void setDataSource(DataSource dataSource) {
      this.dataSource=dataSource;
      }
      public DataSource getDataSource() {
      return dataSource;
      }
  
      JdbcTemplate jdbcTemplate=new JdbcTemplate(dataSource);
      @RequestMapping(value="/Login",method=RequestMethod.POST)
      public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) {                       
                  String userName = request.getParameter("userName");
              String password=request.getParameter("password");
              try {
              String selectQuery=("SELECT * FROM USERDETAILS WHERE NAME='"+userName+"'AND PASSWORD='"+password+"'");
                  check=jdbcTemplate.update(selectQuery,new Object[]{});  
                  System.out.println(check);
                  if(check!=0) {
                  response.sendRedirect("DvdController");
  
                  }
              }
  
              catch(IOException e) {
              e.printStackTrace();            
              }
  
              return new ModelAndView("failure"); 
      }
  </code></pre>
  
  <p>My error is like as below:</p>
  
  <p>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'LoginController' defined in ServletContext resource [/WEB-INF/dvd-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [LoginController]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: Property 'dataSource' is required
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(support:AbstractAutowireCapableBeanFactory.java):965)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(support:AbstractAutowireCapableBeanFactory.java):911)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(support:AbstractAutowireCapableBeanFactory.java):485)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(support:AbstractAutowireCapableBeanFactory.java):456)
      org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(support:AbstractBeanFactory.java):291)
      org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(support:DefaultSingletonBeanRegistry.java):222)
      org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(support:AbstractBeanFactory.java):288)
      org.springframework.beans.factory.support.AbstractBeanFactory.getBean(support:AbstractBeanFactory.java):190)
      org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(support:DefaultListableBeanFactory.java):580)
      org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
      org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)</p>
  
  <p>root cause</p>
  
  <p>org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [LoginController]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: Property 'dataSource' is required
      org.springframework.beans.BeanUtils.instantiateClass(beans:BeanUtils.java):141)
      org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(support:SimpleInstantiationStrategy.java):74)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(support:AbstractAutowireCapableBeanFactory.java):958)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(support:AbstractAutowireCapableBeanFactory.java):911)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(support:AbstractAutowireCapableBeanFactory.java):485)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(support:AbstractAutowireCapableBeanFactory.java):456)
      org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(support:AbstractBeanFactory.java):291)
      org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(support:DefaultSingletonBeanRegistry.java):222)
      org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(support:AbstractBeanFactory.java):288)
      org.springframework.beans.factory.support.AbstractBeanFactory.getBean(support:AbstractBeanFactory.java):190)
      org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(support:DefaultListableBeanFactory.java):580)
      org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
      org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)</p>
  
  <p>root cause</p>
  
  <p>java.lang.IllegalArgumentException: Property 'dataSource' is required
      org.springframework.jdbc.support.JdbcAccessor.afterPropertiesSet(support:JdbcAccessor.java):134)
      org.springframework.jdbc.core.JdbcTemplate.(core:JdbcTemplate.java):164)
      LoginController.(LoginController.java:29)
      sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
      sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
      java.lang.reflect.Constructor.newInstance(Constructor.java:513)
      org.springframework.beans.BeanUtils.instantiateClass(beans:BeanUtils.java):126)
      org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(support:SimpleInstantiationStrategy.java):74)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(support:AbstractAutowireCapableBeanFactory.java):958)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(support:AbstractAutowireCapableBeanFactory.java):911)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(support:AbstractAutowireCapableBeanFactory.java):485)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(support:AbstractAutowireCapableBeanFactory.java):456)
      org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(support:AbstractBeanFactory.java):291)
      org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(support:DefaultSingletonBeanRegistry.java):222)
      org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(support:AbstractBeanFactory.java):288)
      org.springframework.beans.factory.support.AbstractBeanFactory.getBean(support:AbstractBeanFactory.java):190)
      org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(support:DefaultListableBeanFactory.java):580)
      org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
      org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)
      org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)</p>
  
  <p>please help me to clear this!!!</p>