title: Caused by: org.springframework.data.mapping.model.MappingException: No property territoryID found on com.common.model.EmployeeTerritory! - Spring Boot
body: <p>I am developing <code>Spring Boot MongoDB</code> example. In this example, I am trying to get TerritoryID by spring-data-mongo repository query and facing below error. Please guide</p>
  
  <pre><code>Caused by: org.springframework.data.mapping.model.MappingException: No property territoryID found on com.common.model.EmployeeTerritory!
      at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentPropertyPath(AbstractMappingContext.java:236) ~[spring-data-commons-1.9.3.RELEASE.jar:na]
      at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentPropertyPath(AbstractMappingContext.java:214) ~[spring-data-commons-1.9.3.RELEASE.jar:na]
      at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentPropertyPath(AbstractMappingContext.java:202) ~[spring-data-commons-1.9.3.RELEASE.jar:na]
      at org.springframework.data.mongodb.repository.query.MongoQueryCreator.create(MongoQueryCreator.java:109) ~[spring-data-mongodb-1.6.3.RELEASE.jar:na]
      at org.springframework.data.mongodb.repository.query.MongoQueryCreator.create(MongoQueryCreator.java:55) ~[spring-data-mongodb-1.6.3.RELEASE.jar:na]
      at org.springframework.data.repository.query.parser.AbstractQueryCreator.createCriteria(AbstractQueryCreator.java:109) ~[spring-data-commons-1.9.3.RELEASE.jar:na]
      at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:88) ~[spring-data-commons-1.9.3.RELEASE.jar:na]
      at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:73) ~[spring-data-commons-1.9.3.RELEASE.jar:na]
      at org.springframework.data.mongodb.repository.query.PartTreeMongoQuery.createQuery(PartTreeMongoQuery.java:75) ~[spring-data-mongodb-1.6.3.RELEASE.jar:na]
      at org.springframework.data.mongodb.repository.query.AbstractMongoQuery.execute(AbstractMongoQuery.java:86) ~[spring-data-mongodb-1.6.3.RELEASE.jar:na]
      at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:415) ~[spring-data-commons-1.9.3.RELEASE.jar:na]
      at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:393) ~[spring-data-commons-1.9.3.RELEASE.jar:na]
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.1.7.RELEASE.jar:4.1.7.RELEASE]
      at org.springframework.data.repository.core.support.RepositoryFactorySupport$DefaultMethodInvokingMethodInterceptor.invoke(RepositoryFactorySupport.java:506) ~[spring-data-commons-1.9.3.RELEASE.jar:na]
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.1.7.RELEASE.jar:4.1.7.RELEASE]
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) ~[spring-aop-4.1.7.RELEASE.jar:4.1.7.RELEASE]
      at com.sun.proxy.$Proxy35.findByTerritoryID(Unknown Source) ~[na:na]
      at com.common.service.EmployeeTerritoryServiceImpl.findByTerritoryID(EmployeeTerritoryServiceImpl.java:18) ~[classes/:na]
      at com.common.main.MainController.run(MainController.java:51) ~[classes/:na]
      at org.springframework.boot.SpringApplication.runCommandLineRunners(SpringApplication.java:672) [spring-boot-1.2.5.RELEASE.jar:1.2.5.RELEASE]
      ... 5 common frames omitted
  16-03-22 22:33:38 [main] INFO  o.s.c.a.AnnotationConfigApplicationContext - Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@576d5deb: startup date [Tue Mar 22 22:33:26 IST 2016]; root of context hierarchy
  16-03-22 22:33:38 [main] INFO  o.s.j.e.a.AnnotationMBeanExporter - Unregistering JMX-exposed beans on shutdown
  Exception in thread "main" java.lang.IllegalStateException: Failed to execute CommandLineRunner
      at org.springframework.boot.SpringApplication.runCommandLineRunners(SpringApplication.java:675)
      at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:690)
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:321)
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
      at com.common.main.Main.main(Main.java:17)
  </code></pre>
  
  <p>The code I developed:
  EmployeeTerritory.java</p>
  
  <pre><code>@Document(collection="employee-territories")
  public class EmployeeTerritory {
  
      @Id
      private ObjectId id;
      @Field
      private String EmployeeID;
      @Field(value="TerritoryID")
      private Integer TerritoryID;
      // setters and getters
  }
  </code></pre>
  
  <p>EmployeeTerritoryRepository.java</p>
  
  <pre><code>public interface EmployeeTerritoryRepository extends CrudRepository&lt;EmployeeTerritory, String&gt;{
      EmployeeTerritory findByTerritoryID(Integer territoryID);
  }
  </code></pre>
  
  <p>EmployeeTerritoryService.java</p>
  
  <pre><code>public interface EmployeeTerritoryService {
      EmployeeTerritory findByTerritoryID(Integer territoryID);
  }
  </code></pre>
  
  <p>EmployeeTerritoryServiceImpl.java</p>
  
  <pre><code>@Component
  public class EmployeeTerritoryServiceImpl implements EmployeeTerritoryService{
  
      @Autowired
      private EmployeeTerritoryRepository employeeTerritoryRepository;
  
  
      @Override
      public EmployeeTerritory findByTerritoryID(Integer territoryID) {
          EmployeeTerritory et = employeeTerritoryRepository.findByTerritoryID(territoryID);
          return et;
      }
  }
  </code></pre>
  
  <p>MainController.java</p>
  
  <pre><code>@Controller
  public class MainController implements CommandLineRunner {
      private Logger LOGGER = Logger.getLogger(MainController.class);
  
      @Autowired
      private EmployeeTerritoryService etService;
  
      @Override
      public void run(String... args) throws Exception {
          LOGGER.info("~~ STARTED ~~");
          // Find employee-territories
          EmployeeTerritory et = etService.findByTerritoryID(19713);
          LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~");
          LOGGER.info("EmployeeID    : "+et.getEmployeeID());
          LOGGER.info("TerritoryID   : "+et.getTerritoryID());
      }
  }
  </code></pre>
  
  <p>Main.java</p>
  
  <pre><code>@Configuration
  @EnableAutoConfiguration
  @EnableMongoRepositories("com.common.repository")
  @ComponentScan({"com.common.main", "com.common.service"})
  public class Main {
  
      public static void main(String[] args) {
          SpringApplication.run(Main.class, args);
      }
  }
  </code></pre>
  
  <p>application.properties</p>
  
  <pre><code># MONGODB Config
  spring.data.mongodb.host=localhost
  spring.data.mongodb.port=27017
  spring.data.mongodb.uri=mongodb://localhost/boot
  spring.data.mongodb.repositories.enabled=true
  
  logging.level.com.altruista.guidingsigns=INFO
  logging.level.org.springframework=INFO
  </code></pre>
  
  <p>DB Collection:
  <a href="https://i.stack.imgur.com/oTfzl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oTfzl.png" alt="enter image description here"></a></p>