title: Spring boot Controller is not able to find the bean class
body: <hr>
  
  <p>I am new at Spring and i am tring to built a simple registration form using spring boot and storing user information in mysql database using jpa. </p>
  
  <p><strong>This is my error stack.</strong></p>
  
  <pre><code>----------
  
  
    .   ____          _            __ _ _
   /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
  ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
   \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
    '  |____| .__|_| |_|_| |_\__, | / / / /
   =========|_|==============|___/=/_/_/_/
   :: Spring Boot ::        (v1.5.3.RELEASE)
  
  2017-06-05 12:34:53.392  INFO 9128 --- [           main] com.mohit.LoanapimainApplication         : Starting LoanapimainApplication on MOHIT with PID 9128 (C:\Users\admin\Documents\workspace-sts-3.8.4.RELEASE\loanapimain\target\classes started by admin in C:\Users\admin\Documents\workspace-sts-3.8.4.RELEASE\loanapimain)
  2017-06-05 12:34:53.407  INFO 9128 --- [           main] com.mohit.LoanapimainApplication         : No active profile set, falling back to default profiles: default
  2017-06-05 12:34:53.815  INFO 9128 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@396c1e: startup date [Mon Jun 05 12:34:53 IST 2017]; root of context hierarchy
  2017-06-05 12:34:55.754  INFO 9128 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
  2017-06-05 12:34:55.772  INFO 9128 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
  2017-06-05 12:34:55.772  INFO 9128 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.14
  2017-06-05 12:34:56.006  INFO 9128 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
  2017-06-05 12:34:56.006  INFO 9128 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2207 ms
  2017-06-05 12:34:56.163  INFO 9128 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
  2017-06-05 12:34:56.163  INFO 9128 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
  2017-06-05 12:34:56.163  INFO 9128 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
  2017-06-05 12:34:56.163  INFO 9128 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
  2017-06-05 12:34:56.163  INFO 9128 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
  2017-06-05 12:34:56.756  INFO 9128 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
  2017-06-05 12:34:56.771  INFO 9128 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
      name: default
      ...]
  2017-06-05 12:34:56.881  INFO 9128 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.0.12.Final}
  2017-06-05 12:34:56.881  INFO 9128 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
  2017-06-05 12:34:56.881  INFO 9128 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
  2017-06-05 12:34:56.927  INFO 9128 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
  2017-06-05 12:34:57.052  INFO 9128 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
  2017-06-05 12:34:57.615  INFO 9128 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
  2017-06-05 12:34:57.631  WARN 9128 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'user'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.mohit.beans.User' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  2017-06-05 12:34:57.631  INFO 9128 --- [           main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
  2017-06-05 12:34:57.631  INFO 9128 --- [           main] o.apache.catalina.core.StandardService   : Stopping service Tomcat
  2017-06-05 12:34:57.646  INFO 9128 --- [           main] utoConfigurationReportLoggingInitializer : 
  
  Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
  2017-06-05 12:34:57.740 ERROR 9128 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 
  
  ***************************
  APPLICATION FAILED TO START
  ***************************
  
  Description:
  
  Field user in com.mohit.Controllers.UserController required a bean of type 'com.mohit.beans.User' that could not be found.
  </code></pre>
  
  <p>Action:</p>
  
  <p>Consider defining a bean of type 'com.mohit.beans.User' in your configuration.</p>
  
  <hr>
  
  <p><strong>Contoller</strong>`</p>
  
  <pre><code>package com.mohit.Controllers;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestParam;
  import com.mohit.beans.User;
  
  import com.mohit.Services.createuser;
  
  @Controller
  public class UserController {
  
  
      @Autowired(required=true)
      private User user;
      @Autowired(required=true)
      private createuser create;
  
      @RequestMapping("/")
      public String sayhi(){
  
  
          return "index";
  
      }
  
      @RequestMapping("/index")
      public String Createuser(@RequestParam(value="uname") String name,@RequestParam(value="pass") String pass, Model model){
          user.setUname(name);
          user.setPass(pass);
          create.adduser(user);
          return "result";
  
      }
  
      public String AuthUser(@RequestParam(value="name") String name,@RequestParam(value="pass") String pass, Model model){
  
  
          return "mainpage";
  
      }
  
  
  
  }
  
  
  
  ----------
  </code></pre>
  
  <h2><strong>bean class</strong></h2>
  
  <pre><code> --------------
  
  
  
  ----------
  
      package com.mohit.beans;
  
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  
  @Entity
  public class User {
  
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      private int id;
      private String uname;
      private String pass;
      public User(String uname, String pass) {
          super();
  
          this.uname = uname;
          this.pass = pass;
      }
  
  
      public User() {
          super();
      }
  
  
      public int getId() {
          return id;
      }
      public void setId(int id) {
          this.id = id;
      }
  
  
      public String getUname() {
          return uname;
      }
      public void setUname(String uname) {
          this.uname = uname;
      }
      public String getPass() {
          return pass;
      }
      public void setPass(String pass) {
          this.pass = pass;
      }
  
  
      @Override
      public String toString() {
          return "User [id=" + id + ", uname=" + uname + ", pass=" + pass + "]";
      }
  
  
  }
  
  
  
  ----------
  </code></pre>
  
  <h2><strong>Service class</strong></h2>
  
  <pre><code>----------
  package com.mohit.Services;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  
  import com.mohit.Repo.userrepo;
  import com.mohit.beans.User;
  
  @Service
  public class createuser {
  
      @Autowired
      private userrepo Userrepo;
  
      public void adduser(User user)
      {
          Userrepo.save(user);
      }
  
  
  }
  
  
  
  
  ----------
  </code></pre>
  
  <h2><strong>Repository</strong></h2>
  
  <pre><code>--------------
  
  
  
  ----------
  
      package com.mohit.Repo;
  import org.springframework.data.repository.PagingAndSortingRepository;
  import com.mohit.beans.User;
  
  
  public interface userrepo extends PagingAndSortingRepository&lt;User,String&gt; {
  
  }
  
  
  ----------
  </code></pre>
  
  <h1><strong>pom.xml</strong>`</h1>
  
  <pre><code>----------
  
  
  ?xml version="1.0" encoding="UTF-8"?&gt;
  &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/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.mohit&lt;/groupId&gt;
      &lt;artifactId&gt;loanapimain&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;name&gt;loanapimain&lt;/name&gt;
      &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;1.5.3.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
  
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  
  &lt;/project&gt;
  
  
  ----------
  </code></pre>
  
  <h2><strong>Application.config</strong></h2>
  
  <pre><code>    spring.datasource.url=jdbc:mysql://localhost/project
  spring.datasource.username=root
  spring.datasource.password=
  spring.datasource.driver-class-name=com.mysql.jdbc.Driver
  
  
  ----------
  </code></pre>
  
  <h2><strong>LoanapiApplication.java</strong>`</h2>
  
  <pre><code>package com.mohit;
  
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  
  @SpringBootApplication
  public class LoanapimainApplication {
  
      public static void main(String[] args) {
          SpringApplication.run(LoanapimainApplication.class, args);
      }
  }
  </code></pre>