title: Unable to solve error of Springboot gradle - required a bean of type 'com.myapp.services.UserDetailRepository' that could not be found
body: <p>I am getting this error when i use <code>@Autowired</code> for my <code>JPA repository interface</code>. I have seen this when i changed to <code>Gradle</code> from <code>Maven</code>. </p>
  
  <p>I used <code>@ComponentScan</code> on my Main class but no luck. Why it is failing in Gradle. </p>
  
  <p><strong>Error Description:</strong></p>
  
  <pre><code>Field userDetailRepository in com.myapp.controllers.UserRestController required a bean of type 'com.myapp.services.UserDetailRepository' that could not be found.
  
  Consider defining a bean of type 'com.myapp.services.UserDetailRepository' in your configuration.
  </code></pre>
  
  <p>My Gradle (private repo renamed)</p>
  
  <pre><code>buildscript {
    repositories {
      maven { url "https://binrepo.private.com/artifactory/platform" }
      maven { url "https://binrepo.private.com/artifactory/jcenter" }
      maven { url "https://binrepo.private.com/artifactory/gradle" }
      maven { url "https://binrepo.private.com/artifactory/maven-central" }
      jcenter()
      mavenCentral()
      maven {
        url "https://plugins.gradle.org/m2/"
      }
    }
    dependencies {    
      classpath "com.target.platform:platform-connector-gradle:1.1.4"
      classpath "org.springframework.boot:spring-boot-gradle-plugin:1.5.18.RELEASE"
  
    }
  }
  
  apply plugin: 'java'
  apply plugin: 'org.springframework.boot'
  apply plugin: 'io.spring.dependency-management'
  apply plugin: 'application'
  apply plugin: "com.target.platform.connector.spring-boot"
  
  repositories {
      maven { url "https://binrepo.private.com/artifactory/platform" }
      maven { url "https://binrepo.private.com/artifactory/jcenter" }
      maven { url "https://binrepo.private.com/artifactory/gradle" }
      maven { url "https://binrepo.private.com/artifactory/maven-central" }
      jcenter()
      mavenCentral()
      maven {
        url "https://plugins.gradle.org/m2/"
      }
    }
  
  sourceSets.main.java.srcDirs = ['src']
  mainClassName = "com.myapp.Main"
  sourceCompatibility = 1.8
  targetCompatibility = 1.8
  
  version = "3"
  
  distTar.version = ""
  
  dependencies {
      compile('org.springframework.boot:spring-boot-autoconfigure',
              'org.springframework.boot:spring-boot-starter',
              "org.springframework.boot:spring-boot-starter-web:1.5.18.RELEASE",
              "org.springframework.boot:spring-boot-starter-data-jpa:1.5.18.RELEASE",
              "org.springframework.boot:spring-boot-starter-data-ldap:1.5.18.RELEASE",
              "org.springframework.boot:spring-boot-starter-mail:1.5.18.RELEASE",
              "org.springframework.boot:spring-boot-starter-validation:1.5.18.RELEASE",
              "org.springframework.boot:spring-boot-devtools",
              "org.postgresql:postgresql",
              "it.ozimov:spring-boot-email-core:0.6.3",
              "org.freemarker:freemarker:2.3.27-incubating",
              "io.springfox:springfox-swagger2:2.9.2",
              "io.springfox:springfox-swagger-ui:2.9.2",
              "io.springfox:springfox-core:2.9.2",
              "io.springfox:springfox-spi:2.9.2")
  
  }
  
  configurations.all {
      exclude module:"spring-boot-starter-logging"
  }
  </code></pre>
  
  <p>My Application bootstrap file</p>
  
  <pre><code>@Configuration
  @SpringBootApplication
  @EnableAutoConfiguration
  public class Main {
    public static void main(String[] args) {
      SpringApplication.run(Main.class);
    }
  }
  </code></pre>
  
  <p>Rest Controller</p>
  
  <pre><code>@RestController
  @RequestMapping("/users")
  public class UserRestController {
  
      @Autowired
      private UserDetailRepository userDetailRepository;
  
      @GetMapping("/{id}")
      public UserDetail get(@PathVariable Integer id) {
           return userDetailRepository.findOne(id);
      }
  }
  </code></pre>
  
  <p><code>UserDetailRepository</code> JPA repository</p>
  
  <pre><code>public interface UserDetailRepository extends JpaRepository&lt;UserDetail, Integer&gt; {
      public UserDetail findOne(Integer id);
  }
  </code></pre>
  
  <p><code>UserDetail</code> Entity Class</p>
  
  <pre><code>@Entity
  @Table(name = "user_detail")
  @XmlRootElement
  public class UserDetail implements Serializable {
  
      private static final long serialVersionUID = 1L;
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Basic(optional = false)
      @Column(name = "id")
      private Integer userId;
      @Size(max = 25)
      @Column(name = "name")
      private String userName;
  
      .........
  
  }
  </code></pre>