title: UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency
body: <p>I'm new to spring MVC. I'm facing <code>UnsatisfiedDependencyException</code>. I have added <code>stereotype annotations</code> but still I'm facing same issue.</p>
  
  <blockquote>
    <p>Exception encountered during context initialization - cancelling
    refresh attempt:
    org.springframework.beans.factory.UnsatisfiedDependencyException:
    Error creating bean with name 'userController': Unsatisfied dependency
    expressed through field 'userService'; nested exception is
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No
    qualifying bean found for dependency
    [com.demo.app.service.UserService]: expected at least 1 bean which
    qualifies as autowire candidate. Dependency annotations:
    {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    looking positive replay.</p>
  </blockquote>
  
  <p><strong>UserController:</strong></p>
  
  <pre><code>@CrossOrigin
  @RestController
  public class UserController {
  
  @Autowired(required=true)
  private UserService userService;
  
  @RequestMapping(value = { "/userSave" },consumes = {"multipart/form-data"}, method = RequestMethod.POST)
  @ResponseBody
  public String saveUserDetails(@RequestPart(value="file",required=false) MultipartFile file,
          @RequestPart("user")User user,
          HttpSession session, HttpServletRequest request,
          HttpServletResponse response){
          System.out.println("data reached...!");
          String result=userService.saveUserData(user,session);
          return result;
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>UserService:</strong></p>
  
  <pre><code>public interface UserService {
       public String saveUserData(User user,HttpSession session);
  }
  </code></pre>
  
  <p><strong>UserServiceImpl:</strong></p>
  
  <pre><code>@Service("userService")
  public class UserServiceImpl implements UserService{
  
  @Autowired
  UserRepository userRepository;
  
  public String saveUserData(User user,HttpSession session){
      String  output;
      Date regDate=new Date();
      user.setRegDate(regDate);
      output= userRepository.saveUserData(user);
      return output;
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>UserRepository:</strong></p>
  
  <pre><code>@Component
  @Transactional
  public class UserRepository  extends BaseRepository{
  
  @Autowired
  protected SessionFactory sessionFactory;
  
  
  public String saveUserData(User user) {
  
      final Session session = (Session) getSessionFactory();
      try {
          session.beginTransaction();
          Query query=session.createQuery("UPDATE User set user_Name =:userName,"
                  + "reg_Date =:regDate,img_Id=:imgId");
          query.setParameter("userName", user.getUserName());
          query.setParameter("regDate", user.getRegDate());
          query.setParameter("imgId", user.getImgId());
          query.setParameter("emailId", user.getImgId());
          session.save(user);
          session.getTransaction().commit();
      } catch (Exception e) {
          e.printStackTrace();
      }
      return null;
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>spring.xml:</strong></p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
      xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
                      http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
                      http://www.springframework.org/schema/context 
                      http://www.springframework.org/schema/context/spring-context-4.0.xsd
                      http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
                      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
                      "&gt;
  
      &lt;context:annotation-config /&gt;
  
      &lt;context:component-scan base-package="com.demo.app" /&gt;
      &lt;mvc:default-servlet-handler /&gt;
  
      &lt;mvc:annotation-driven&gt;
          &lt;mvc:message-converters register-defaults="true"&gt;
              &lt;bean class="org.springframework.http.converter.StringHttpMessageConverter"&gt;
                  &lt;property name="supportedMediaTypes" value="text/plain;charset=UTF-8" /&gt;
              &lt;/bean&gt;
          &lt;/mvc:message-converters&gt;
      &lt;/mvc:annotation-driven&gt;
  
      &lt;bean id="jspViewResolver"
          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="/WEB-INF/html/" /&gt;
          &lt;property name="suffix" value="html" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="dataSource"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
          &lt;property name="url" value="jdbc:mysql://localhost:3306/UserDB" /&gt;
          &lt;property name="username" value="root" /&gt;
          &lt;property name="password" value="password" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="sessionFactory"
          class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="annotatedClasses"&gt;
              &lt;list&gt;
                  &lt;value&gt;com.demo.app.model.User&lt;/value&gt;
  
              &lt;/list&gt;
          &lt;/property&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQL5Dialect&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
                  &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
      &lt;bean id="transactionManager"
          class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
      &lt;/bean&gt;
      &lt;bean
          class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"&gt;
          &lt;property name="exceptionMappings"&gt;
              &lt;props&gt;
                  &lt;prop key="java.lang.Exception"&gt;Error&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
      &lt;bean id="multipartResolver"
          class="org.springframework.web.multipart.commons.CommonsMultipartResolver"&gt;
          &lt;property name="maxUploadSize" value="2097152" /&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>Error:</strong></p>
  
  <pre><code>SEVERE: Context initialization failed
  org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean found for dependency [com.demo.app.service.UserService]: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:569)
      at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:349)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1219)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:751)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
      at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
  </code></pre>
  
  <p>Please help me,</p>
  
  <p>Thank you</p>