title: Java Spring Boot Application Can Not Detect Mongodb Repository
body: <p>I'm trying to use my mongodb document over MongoRepository in Spring Boot Application for implementing Spring State Machines with Persistence.</p>
  
  <p>The problem is, when I Autowire my MongoRepository class in Spring Application class, it says:</p>
  
  <pre><code>Caused by: java.lang.NoClassDefFoundError: org/springframework/data/mongodb/repository/MongoRepository
      at java.base/java.lang.ClassLoader.defineClass1(Native Method)
      at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
      at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151)
      at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:802)
      at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:700)
      at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:623)
      at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
      at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
      at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
      at java.base/java.lang.Class.getDeclaredFields0(Native Method)
      at java.base/java.lang.Class.privateGetDeclaredFields(Class.java:3067)
      at java.base/java.lang.Class.getDeclaredFields(Class.java:2254)
      at org.springframework.util.ReflectionUtils.getDeclaredFields(ReflectionUtils.java:755)
      ... 20 common frames omitted
  Caused by: java.lang.ClassNotFoundException: org.springframework.data.mongodb.repository.MongoRepository
      at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
      at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
      at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
      ... 33 common frames omitted
  </code></pre>
  
  <p>Thanks a lot for your help in advance :)</p>
  
  <p>pom.xml file:</p>
  
  <pre><code>    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-data-mongodb&lt;/artifactId&gt;
          &lt;version&gt;2.1.7.RELEASE&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.statemachine&lt;/groupId&gt;
          &lt;artifactId&gt;spring-statemachine-data-mongodb&lt;/artifactId&gt;
            &lt;version&gt;2.1.3.RELEASE&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
            &lt;artifactId&gt;spring-data-mongodb&lt;/artifactId&gt;
            &lt;version&gt;2.1.10.RELEASE&lt;/version&gt;
        &lt;/dependency&gt;
  </code></pre>
  
  <hr>
  
  <p>Custom MongoRepository:</p>
  
  <pre><code>package com.itu.celikelni.spring.boot.statemachine.data;
  
  import com.itu.celikelni.spring.boot.statemachine.data.PaymentDbObject;
  import org.springframework.data.mongodb.repository.MongoRepository;
  import org.springframework.stereotype.Repository;
  
  
  @Repository
  public interface PaymentRepository extends MongoRepository&lt;PaymentDbObject, Integer&gt; {
  
  }
  </code></pre>
  
  <hr>
  
  <p>Application</p>
  
  <pre><code>package com.itu.celikelni.spring.boot.statemachine;
  import com.itu.celikelni.spring.boot.statemachine.entity.Events;
  import com.itu.celikelni.spring.boot.statemachine.entity.States;
  import com.itu.celikelni.spring.boot.statemachine.entity.Payment;
  import com.itu.celikelni.spring.boot.statemachine.service.PaymentService;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.boot.CommandLineRunner;
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.statemachine.StateMachine;
  import org.springframework.statemachine.persist.StateMachinePersister;
  import com.itu.celikelni.spring.boot.statemachine.data.PaymentRepository;
  import com.itu.celikelni.spring.boot.statemachine.data.PaymentDbObject;
  import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
  
  @ComponentScan("com.itu.celikelni.spring.boot.statemachine.data")
  @EnableMongoRepositories("com.itu.celikelni.spring.boot.statemachine.data")
  @SpringBootApplication
  public class Application implements CommandLineRunner {
  
      @Autowired
      private StateMachine&lt;States, Events&gt; stateMachine;
  
      @Autowired
      private StateMachinePersister&lt;States, Events, Integer&gt; stateMachinePersister;
  
      @Autowired
      private PaymentService paymentService;
  
      @Autowired
      private PaymentRepository paymentRepository;
  </code></pre>