title: Intellij Idea - Could not autowire. No beans of 'ApplicationRepository' type found. less... (Ctrl+F1) Checks autowiring problems in a bean class
body: <p>I am Java newbie.</p>
  
  <p>I am making this <a href="http://confluence.jetbrains.com/display/IntelliJIDEA/Getting+Started+with+Spring+MVC%2C+Hibernate+and+JSON" rel="nofollow">tutorial</a> (Spring MVC + Hibernate + Tomcat)</p>
  
  <p>Everything goes fine till now. When I tried to make a <code>ApplicationController</code> I could not autowire <code>ApplicationRepository</code>.</p>
  
  <p>I get this error message and <code>404</code> error code when I deploy application:</p>
  
  <pre><code>Could not autowire. No beans of 'ApplicationRepository' type found. less...     
  (Ctrl+F1) 
  Checks autowiring problems in a bean class.
  </code></pre>
  
  <p>Ok talk is cheap. </p>
  
  <p>Here goes the <strong>repo</strong> (github!): <a href="https://github.com/maciejkowalski/sample-spring-app" rel="nofollow">https://github.com/maciejkowalski/sample-spring-app</a></p>
  
  <p>Tomcat <strong>stacktrace</strong>: <a href="https://gist.github.com/maciejkowalski/c7512d82feb75fcebd5f" rel="nofollow">https://gist.github.com/maciejkowalski/c7512d82feb75fcebd5f</a></p>
  
  <p>Here is the <strong>code</strong>:</p>
  
  <p><strong>root/src/main/java/wzpweb/</strong></p>
  
  <pre><code>package wzpweb;
  
  import javax.persistence.*;
  
  @Entity(name = "applications")
  public class Application {
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Long id;
  
      @Basic
      private String name;
  
      @Basic
      private String ip;
  
      @Basic
      private Boolean alive;
  
      @Basic
      private Integer port;
  
      public Long getId() {
          return id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getIp() {
          return ip;
      }
  
      public void setIp(String ip) {
          this.ip = ip;
      }
  
      public Boolean getAlive() {
          return alive;
      }
  
      public void setAlive(Boolean alive) {
          this.alive = alive;
      }
  
      public Integer getPort() {
          return port;
      }
  
      public void setPort(Integer port) {
          this.port = port;
      }
  
  }
  </code></pre>
  
  <hr>
  
  <pre><code>package wzpweb;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.ModelMap;
  import org.springframework.validation.BindingResult;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  
  @Controller
  public class ApplicationController {
  
      @Autowired
      private ApplicationRepository applicationRepository;
      // THIS IS NOT WORKING !! ACHTUNG!
  
      @RequestMapping(value = "/", method = RequestMethod.GET)
      public String listApplications(ModelMap model) {
          model.addAttribute("application", new Application());
          model.addAttribute("applications", applicationRepository.findAll());
          return "users";
      }
  
  }
  </code></pre>
  
  <hr>
  
  <pre><code>package wzpweb;
  
  import org.springframework.data.jpa.repository.JpaRepository;
  
  public interface ApplicationRepository extends JpaRepository&lt;Application, Long&gt; {
  }
  </code></pre>
  
  <p><strong>root/src/main/webapp/WEB-INF/mvc-dispatcher-servlet.xml</strong></p>
  
  <pre><code>&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:jpa="http://www.springframework.org/schema/data/jpa" xmlns:tx="http://www.springframework.org/schema/tx"
         xsi:schemaLocation="http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"&gt;
  
      &lt;context:component-scan base-package="wzpweb"/&gt;
  
      &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="prefix" value="/WEB-INF/pages/"/&gt;
          &lt;property name="suffix" value=".jsp"/&gt;
      &lt;/bean&gt;
  
      &lt;jpa:repositories base-package="wzpweb"/&gt;
  
      &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"&gt;
          &lt;property name="persistenceUnitName" value="defaultPersistenceUnit"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
          &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
      &lt;/bean&gt;
  
      &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <hr>
  
  <p><strong>root/src/main/webapp/WEB-INF/web.xml</strong></p>
  
  <pre><code>&lt;web-app version="2.4"
      xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
      http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt;
  
      &lt;display-name&gt;Spring MVC Application&lt;/display-name&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <hr>
  
  <p><strong>root/src/main/resources/META-INF/persistance.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt;
      &lt;persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL"&gt;
          &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
          &lt;properties&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/&gt;
              &lt;property name="hibernate.connection.url" value="jdbc:postgresql://localhost/sample"/&gt;
              &lt;property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/&gt;
              &lt;property name="hibernate.connection.username" value="postgres" /&gt;
              &lt;property name="hibernate.connection.password" value="123" /&gt;
              &lt;property name="hibernate.show_sql" value="true"/&gt;
              &lt;property name="hibernate.format_sql" value="true"/&gt;
              &lt;property name="hibernate.hbm2ddl.auto" value="create-drop" /&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p><strong>root/pom.xml</strong></p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;com.springapp&lt;/groupId&gt;
      &lt;artifactId&gt;WZP_aplikacja_web&lt;/artifactId&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;WZP_aplikacja_web&lt;/name&gt;
  
      &lt;properties&gt;
          &lt;spring.version&gt;3.2.2.RELEASE&lt;/spring.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&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;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;servlet-api&lt;/artifactId&gt;
              &lt;version&gt;3.0&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.1&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-test&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;4.8.2&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;jstl&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.data&lt;/groupId&gt;
              &lt;artifactId&gt;spring-data-jpa&lt;/artifactId&gt;
              &lt;version&gt;1.2.0.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate.javax.persistence&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-jpa-2.0-api&lt;/artifactId&gt;
              &lt;version&gt;1.0.1.Final&lt;/version&gt;
          &lt;/dependency&gt;
  
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
              &lt;version&gt;4.2.0.Final&lt;/version&gt;
          &lt;/dependency&gt;
  
  
          &lt;dependency&gt;
              &lt;groupId&gt;postgresql&lt;/groupId&gt;
              &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
              &lt;version&gt;9.1-901.jdbc4&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;finalName&gt;WZP_aplikacja_web&lt;/finalName&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.7&lt;/source&gt;
                      &lt;target&gt;1.7&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
                  &lt;configuration&gt;
                      &lt;includes&gt;
                          &lt;include&gt;**/*Tests.java&lt;/include&gt;
                      &lt;/includes&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT #1</strong></p>
  
  <p>I have edited <code>web.xml</code> and added code:</p>
  
  <pre><code>&lt;web-app version="2.4"
      xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
      http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt;
  
      &lt;display-name&gt;Spring MVC Application&lt;/display-name&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>But now I get  <code>Element listener-class is not allowed her</code> from Intellij IDEA.</p>
  
  <p>And my app even doesnt deploy.</p>
  
  <hr>
  
  <p><strong>EDIT #2</strong></p>
  
  <p>Well problem still occurs.</p>
  
  <p>I renamed <code>persistance.xml</code> to <code>persistence.xml</code>.</p>
  
  <p>Restarted Intellij idea and still getting this error.</p>
  
  <p>Maybe this is a bug?</p>
  
  <p>I will probably surrender with this Spring stuff, it's beyond me...</p>