title: Could not autowire field/expected at least 1 bean which qualifies as autowire candidate
body: <p>I am pretty new to Spring and although I have used it for a couple of projects before and I've seen a lot of similar questions, I can't figure out what is wrong with this exception: </p>
  
  <pre><code>SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'applicationController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public service.UserServiceI controller.ApplicationController.userService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [service.UserServiceI] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=userService)}
  </code></pre>
  
  <p>This is the relevant part of the stack trace.</p>
  
  <p>Here is my controller class:</p>
  
  <pre><code>@Controller
  @RequestMapping("/")
  public class ApplicationController {
  
  @Autowired 
  @Qualifier("userService")
  public UserServiceI userService;
  }
  </code></pre>
  
  <p>This is my UserService interface:</p>
  
  <pre><code>public interface UserService {
     //methods
  }
  </code></pre>
  
  <p>And the implementation:</p>
  
  <pre><code>@Service("userService")
  public class UserServiceI implements UserService{
  
  @Autowired
  private UserDao dao;
  
  //methods
  }
  </code></pre>
  
  <p>Here is my XML configuration file:</p>
  
  <pre><code>&lt;context:component-scan base-package="configuration"&gt;
  &lt;/context:component-scan&gt;
  
  
  &lt;bean id="resView" 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/" /&gt;
      &lt;property name="suffix" value=".jsp" /&gt;
  &lt;/bean&gt;
  &lt;mvc:default-servlet-handler/&gt;
  &lt;mvc:resources location="/resources/css/" mapping="/resources/css/*"&gt;
  &lt;/mvc:resources&gt;
  &lt;mvc:resources location="/resources/js/" mapping="/resources/js/*"&gt;
  &lt;/mvc:resources&gt;
  &lt;context:annotation-config&gt;&lt;/context:annotation-config&gt;
  &lt;mvc:annotation-driven&gt;&lt;/mvc:annotation-driven&gt;
  &lt;mvc:default-servlet-handler /&gt;
  &lt;context:component-scan base-package="controller"&gt;
  &lt;/context:component-scan&gt;
  
  &lt;context:component-scan base-package="dao"&gt;&lt;/context:component-scan&gt;
  &lt;context:component-scan base-package="model"&gt;&lt;/context:component-scan&gt;
  &lt;context:component-scan base-package="service"
      use-default-filters="true"&gt;
  &lt;/context:component-scan&gt;
  </code></pre>
  
  <p>This is Spring configuration:</p>
  
  <pre><code>@Configuration
  @EnableWebMvc
  @ComponentScan(basePackages = "{configuration, controller, dao, model,    service}")
  public class SpringConfig extends WebMvcConfigurerAdapter{
  
  @Override
  public void configureViewResolvers(ViewResolverRegistry registry) {
       InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
       viewResolver.setViewClass(JstlView.class);
       viewResolver.setPrefix("/WebContent/");
       viewResolver.setSuffix(".jsp");
       registry.viewResolver(viewResolver);
  }
  
  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
      registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
  }
  
  }
  </code></pre>
  
  <p>And Hibernate configuration:</p>
  
  <pre><code>@Configuration
  @EnableTransactionManagement
  @ComponentScan({"configuration", "controller", "dao", "model", "service"})
  @PropertySource(value = {"classpath:appProperties"})
  public class HibernateConfig {
  
  @Autowired
  private Environment environment;
  
  @Bean
  public LocalSessionFactoryBean sessionFactory(){
      LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
      sessionFactory.setDataSource(dataSource());
      sessionFactory.setPackagesToScan(new String[] {"model"});
      sessionFactory.setHibernateProperties(hibernateProperties());
      return sessionFactory;
  }
  
  @Bean
  public DataSource dataSource(){
      DriverManagerDataSource dataSource = new DriverManagerDataSource();
      dataSource.setDriverClassName(environment.getRequiredProperty("jdbc.driverClassName"));
      dataSource.setUrl(environment.getRequiredProperty("jdbc.url"));
      dataSource.setUsername(environment.getRequiredProperty("jdbc.username"));
      dataSource.setPassword(environment.getRequiredProperty("jdbc.password"));
      return dataSource;
  }
  
  @Bean
  public Properties hibernateProperties(){
      Properties hibernateProperties = new Properties();
      hibernateProperties.put("hibernate.dialect",environment.getRequiredProperty("hibernate.dialect"));
      hibernateProperties.put("hibernate.show_sql", environment.getRequiredProperty("hibernate.show_sql"));
      hibernateProperties.put("hibernate.format_sql", environment.getRequiredProperty("hibernate.format_sql"));
      return hibernateProperties;
  }
  
  @Bean
  @Autowired
  public HibernateTransactionManager transactionManager(SessionFactory s) {
      HibernateTransactionManager txManager = new HibernateTransactionManager();
      txManager.setSessionFactory(s);
      return txManager;
  }
  }
  </code></pre>
  
  <p>And pom.xml</p>
  
  <pre><code>&lt;dependencies&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.springframework&lt;/groupId&gt;
      &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
      &lt;version&gt;4.2.0.RELEASE&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.springframework&lt;/groupId&gt;
      &lt;artifactId&gt;spring-tx&lt;/artifactId&gt;
      &lt;version&gt;4.2.0.RELEASE&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
      &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
      &lt;version&gt;2.2.3&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
      &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
      &lt;version&gt;3.1.0&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
      &lt;artifactId&gt;jstl&lt;/artifactId&gt;
      &lt;version&gt;1.2&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.springframework&lt;/groupId&gt;
      &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
      &lt;version&gt;4.2.0.RELEASE&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.springframework&lt;/groupId&gt;
      &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
      &lt;version&gt;4.2.0.RELEASE&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.springframework&lt;/groupId&gt;
      &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
      &lt;version&gt;4.2.0.RELEASE&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.springframework&lt;/groupId&gt;
      &lt;artifactId&gt;spring-beans&lt;/artifactId&gt;
      &lt;version&gt;4.2.0.RELEASE&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.springframework&lt;/groupId&gt;
      &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
      &lt;version&gt;4.2.0.RELEASE&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
      &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
      &lt;version&gt;4.3.6.Final&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;mysql&lt;/groupId&gt;
      &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
      &lt;version&gt;5.1.31&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;javax.servlet.jsp&lt;/groupId&gt;
      &lt;artifactId&gt;jsp-api&lt;/artifactId&gt;
      &lt;version&gt;2.2&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p></p>
  
  <p>I commented the code in Controller and the result was that it was unable to autowire SessionFactory, although it is defined. Please help me!</p>