title: Could not autowire field (Spring mvc - annotations)
body: <p>I can't resolve my problem with injections Spring's beans. I created multi module project with jar module (there are services, dao, ropositories ...) and war module (there are contollers and aplications config). When I start my application on Jboss i get this exception:</p>
  <pre><code>Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'login': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.engineering.pawel.service.UserService com.engineering.pawel.controller.Login.userService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.engineering.pawel.repository.UserRepository com.engineering.pawel.service.UserService.userRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.engineering.pawel.repository.UserRepository] 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)}
  </code></pre>
  <p>It is my web.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;web-app xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee 
            http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd&quot;
      version=&quot;3.0&quot;&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;
              /WEB-INF/spring/root-context.xml,
              /WEB-INF/spring/spring-security.xml
          &lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
              &lt;param-value&gt;/WEB-INF/spring/appServlet/servlet-context.xml&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;!-- ........................................................................... --&gt;
      &lt;!-- Spring Security --&gt;
      &lt;!-- ........................................................................... --&gt;
      &lt;filter&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
      &lt;/filter&gt;
  
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
  
      &lt;persistence-unit-ref&gt;
          &lt;persistence-unit-ref-name&gt;persistence/my-emf&lt;/persistence-unit-ref-name&gt;
          &lt;persistence-unit-name&gt;my-jpa&lt;/persistence-unit-name&gt;
      &lt;/persistence-unit-ref&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  <p>Below there is servlet-context.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;beans:beans xmlns=&quot;http://www.springframework.org/schema/mvc&quot;
      xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:beans=&quot;http://www.springframework.org/schema/beans&quot;
      xmlns:tx=&quot;http://www.springframework.org/schema/tx&quot; xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
      xmlns:jee=&quot;http://www.springframework.org/schema/jee&quot;
      xsi:schemaLocation=&quot;http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
          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/tx
          http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
          http://www.springframework.org/schema/jee
          http://www.springframework.org/schema/jee/spring-jee-4.0.xsd&quot;&gt;
  
  
      &lt;!-- Enables the Spring MVC @Controller programming model --&gt;
  
      &lt;annotation-driven /&gt;
      &lt;context:annotation-config /&gt;
  
      &lt;!-- Handles HTTP GET requests for /resources by efficiently serving 
          up static resources in the ${webappRoot}/resources directory --&gt;
      &lt;resources mapping=&quot;/resources/**&quot; location=&quot;/resources/&quot; /&gt;
  
      &lt;!-- Resolves views selected for rendering by @Controllers to .jsp resources 
          in the /WEB-INF/views directory --&gt;
      &lt;beans:bean
          class=&quot;org.springframework.web.servlet.view.InternalResourceViewResolver&quot;&gt;
          &lt;beans:property name=&quot;prefix&quot; value=&quot;/WEB-INF/views/&quot; /&gt;
          &lt;beans:property name=&quot;suffix&quot; value=&quot;.jsp&quot; /&gt;
      &lt;/beans:bean&gt;
  
      &lt;!-- Configure to plugin JSON as request and response in method handler --&gt;
      &lt;beans:bean
          class=&quot;org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter&quot;&gt;
          &lt;beans:property name=&quot;messageConverters&quot;&gt;
              &lt;beans:list&gt;
                  &lt;beans:ref bean=&quot;jsonMessageConverter&quot; /&gt;
              &lt;/beans:list&gt;
          &lt;/beans:property&gt;
      &lt;/beans:bean&gt;
  
      &lt;!-- Configure bean to convert JSON to POJO and vice versa --&gt;
      &lt;beans:bean id=&quot;jsonMessageConverter&quot;
          class=&quot;org.springframework.http.converter.json.MappingJackson2HttpMessageConverter&quot;&gt;
      &lt;/beans:bean&gt;
  
      &lt;context:component-scan base-package=&quot;com.engineering.pawel&quot; /&gt;
  
  
      &lt;!-- Database configuration --&gt;
      &lt;jee:jndi-lookup id=&quot;dataSource&quot; jndi-name=&quot;java:jboss/datasources/postgreSQL&quot;
          resource-ref=&quot;true&quot; /&gt;
  
      &lt;jee:jndi-lookup id=&quot;entityManagerFactory&quot; jndi-name=&quot;java:comp/env/persistence/my-emf&quot;
          expected-type=&quot;javax.persistence.EntityManagerFactory&quot; /&gt;
  
      &lt;beans:bean id=&quot;transactionManager&quot;
          class=&quot;org.springframework.transaction.jta.JtaTransactionManager&quot;&gt;
          &lt;beans:property name=&quot;transactionManagerName&quot; value=&quot;java:/TransactionManager&quot; /&gt;
      &lt;/beans:bean&gt;
  
      &lt;beans:bean class=&quot;org.springframework.orm.hibernate4.HibernateExceptionTranslator&quot; /&gt;
  &lt;/beans:beans&gt;
  </code></pre>
  <p>Below there is UserRepository.java</p>
  <pre><code>package com.engineering.pawel.repository;
  
  import org.springframework.data.jpa.repository.JpaRepository;
  import org.springframework.stereotype.Repository;
  
  import com.engineering.pawel.pojo.User;
  
  @Repository
  public interface UserRepository extends JpaRepository&lt;User,Integer&gt;{
      
  }
  </code></pre>
  <p>Below there is UserService.java</p>
  <pre><code>@Service
  @Transactional
  public class UserService {
      
      @Autowired
      private UserRepository userRepository;
      
      public void addUser(final String userNick, final String userPassword){
          final User user = new User();
          user.setNick(userNick);
          user.setPassword(userPassword);
          userRepository.saveAndFlush(user);
      }
      
      public List&lt;User&gt; getUsers(){
          return this.userRepository.findAll();
      }
  
  }
  </code></pre>
  <p>And this is Login class:</p>
  <pre><code>@Controller
  public class Login {
      
      @Autowired
      private UserService userService;
  }
  </code></pre>
  <p>I will be very grateful for help.</p>