title: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'loginController'
body: <p>I am new to Spring and I am try to make a application for learning but I am getting problem in Autowiring,I am adding my code. I am working on spring boot.</p>
  
  <p><strong>logincontroller:</strong></p>
  
  <pre><code>            package com.cloudnexus.spring.controller;
  
              import javax.servlet.http.HttpServletRequest;
              import javax.servlet.http.HttpServletResponse;
  
              import org.springframework.beans.factory.annotation.Autowired;
              import org.springframework.stereotype.Controller;
              import org.springframework.web.bind.annotation.ModelAttribute;
              import org.springframework.web.bind.annotation.RequestMapping;
              import org.springframework.web.bind.annotation.RequestMethod;
              import org.springframework.web.servlet.ModelAndView;
  
              import com.cloudnexus.spring.model.Login;
              import com.cloudnexus.spring.model.User;
              import com.cloudnexus.spring.service.UserService;
  
              @Controller
              public class LoginController {
                  @Autowired
                    UserService userService;
  
                  @RequestMapping(value = "/loginProcess", method = RequestMethod.POST)
                    public ModelAndView loginProcess(HttpServletRequest request, HttpServletResponse response,
                    @ModelAttribute("login") Login login) {
                      ModelAndView mav = null;
                      User user = userService.validateUser(login);
                      if (null != user) {
                      mav = new ModelAndView("welcome");
                      mav.addObject("firstname", user.getUsername());
                      } else {
                      mav = new ModelAndView("login");
                      mav.addObject("message", "Username or Password is wrong!!");
                      }
                      return mav;
                    }
  
              }
  
              ////
  </code></pre>
  
  <p><strong>Login POJO:</strong></p>
  
  <pre><code>        package com.cloudnexus.spring.model;
  
          public class Login {
  
              private String username;
              private String password;
              public String getUsername() {
                  return username;
              }
              public void setUsername(String username) {
                  this.username = username;
              }
              public String getPassword() {
                  return password;
              }
              public void setPassword(String password) {
                  this.password = password;
              }
  
  
  
          }
  </code></pre>
  
  <p><strong>User Pojo :</strong></p>
  
  <pre><code>        package com.cloudnexus.spring.model;
  
          public class User {
  
              private String username;
              private String password;
              private int IsActive;
              public String getUsername() {
                  return username;
              }
              public void setUsername(String username) {
                  this.username = username;
              }
              public String getPassword() {
                  return password;
              }
              public void setPassword(String password) {
                  this.password = password;
              }
              public int getIsActive() {
                  return IsActive;
              }
              public void setIsActive(int isActive) {
                  IsActive = isActive;
              }
  
          }
  </code></pre>
  
  <p><strong>UserDao :</strong></p>
  
  <pre><code>    package com.cloudnexus.spring.dao;
  
      import com.cloudnexus.spring.model.Login;
      import com.cloudnexus.spring.model.User;
  
      public interface UserDao {
          User validateUser(Login login);
  
      }
  </code></pre>
  
  <p><strong>UserDaoImpl</strong> </p>
  
  <pre><code>    package com.cloudnexus.spring.dao;
  
      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.jdbc.core.JdbcTemplate;
      import org.springframework.jdbc.core.RowMapper;
  
      import java.sql.ResultSet;
      import java.sql.SQLException;
      import java.util.List;
  
      import javax.sql.DataSource;
      import com.cloudnexus.spring.model.Login;
      import com.cloudnexus.spring.model.User;
  
      public class UserDaoImpl implements UserDao{
  
  
          @Autowired
            DataSource datasource;
            @Autowired
            JdbcTemplate jdbcTemplate;
          public User validateUser(Login login) {
              String sql = "select * from users where username='" + login.getUsername() + "' and password='" + login.getPassword()
              + "'";
              List&lt;User&gt; users = jdbcTemplate.query(sql, new UserMapper());
              return users.size() &gt; 0 ? users.get(0) : null;
          }
  
      }
  
  
      class UserMapper implements RowMapper&lt;User&gt; {
            public User mapRow(ResultSet rs, int arg1) throws SQLException {
              User user = new User();
              user.setUsername(rs.getString("Name"));
              user.setPassword(rs.getString("Password"));
              user.setIsActive(rs.getInt("IsActive"));
  
              return user;
            }
          }
  </code></pre>
  
  <p><strong>UserService :</strong> </p>
  
  <pre><code>    package com.cloudnexus.spring.service;
  
      import com.cloudnexus.spring.model.Login;
      import com.cloudnexus.spring.model.User;
  
      public interface UserService {
          User validateUser(Login login);
  
      }
  </code></pre>
  
  <p><strong>UserServiceImpl</strong> </p>
  
  <pre><code>    package com.cloudnexus.spring.service;
  
      import org.springframework.beans.factory.annotation.Autowired;
  
      import com.cloudnexus.spring.dao.UserDao;
      import com.cloudnexus.spring.model.Login;
      import com.cloudnexus.spring.model.User;
  
      public class UserServiceImpl implements UserService{
           @Autowired
            public UserDao userDao;
          public User validateUser(Login login) {
              return userDao.validateUser(login);
          }
  
      }
  </code></pre>
  
  <p><strong>spring bean configuration file :</strong></p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;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"&gt;
  
       &lt;context:component-scan base-package="com.cloudnexus.spring" /&gt;
          &lt;context:annotation-config /&gt;
          &lt;bean id="userService" class="com.cloudnexus.spring.service.UserServiceImpl"&gt;
              &lt;property name="userService" ref="userService"&gt;&lt;/property&gt;
          &lt;/bean&gt;
  
          &lt;bean name="userDao" class="com.cloudnexus.spring.dao.UserDaoImpl"&gt;
              &lt;property name="dataSource" ref="dataSource"&gt;&lt;/property&gt;
          &lt;/bean&gt;
  
          &lt;bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"&gt;
              &lt;property name="dataSource" ref="datasource" /&gt;
          &lt;/bean&gt;
  
          &lt;bean id="dataSource"
              class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
              &lt;property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" /&gt;
              &lt;property name="url" value=";DatabaseName=" /&gt;
              &lt;property name="username" value="" /&gt;
              &lt;property name="password" value="" /&gt;
          &lt;/bean&gt;
  
      &lt;/beans&gt;
  </code></pre>
  
  <ol>
  <li>@Autowired to LoginBean loginBean;</li>
  <li>Created getter setter of LoginBean in Controller class and autowired setters;</li>
  <li><p>Created constructor of Controller and autowired, as given in above code;</p>
  
  <p><strong>Below is the error which I am getting :</strong></p>
  
  <pre><code>org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'loginController': Unsatisfied dependency expressed through field 'userService': Error creating bean with name 'userService': Unsatisfied dependency expressed through field 'userDao': Error creating bean with name 'userDao' defined in ServletContext resource [/WEB-INF/springBeanConfiguration.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'dataSource' of bean class [com.cloudnexus.spring.dao.UserDaoImpl]: Bean property 'dataSource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao' defined in ServletContext resource [/WEB-INF/springBeanConfiguration.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'dataSource' of bean class [com.cloudnexus.spring.dao.UserDaoImpl]: Bean property 'dataSource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userService': Unsatisfied dependency expressed through field 'userDao': Error creating bean with name 'userDao' defined in ServletContext resource [/WEB-INF/springBeanConfiguration.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'dataSource' of bean class [com.cloudnexus.spring.dao.UserDaoImpl]: Bean property 'dataSource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao' defined in ServletContext resource [/WEB-INF/springBeanConfiguration.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'dataSource' of bean class [com.cloudnexus.spring.dao.UserDaoImpl]: Bean property 'dataSource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
  </code></pre>
  
  <p>org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:569)
  org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
  org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:349)
  org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
  org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
  org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
  org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
  org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
  org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
  org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
  org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:776)
  org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
  org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
  org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
  org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634)
  org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682)
  org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553)
  org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
  org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
  javax.servlet.GenericServlet.init(GenericServlet.java:160)
  org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
  org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
  org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
  org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
  org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
  org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
  org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
  java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  java.lang.Thread.run(Thread.java:748)</p></li>
  </ol>