title: Spring Data Rest Not Mapped
body: <p>I am trying to use spring data rest. I have included its dependency in pom and defined following bean but no mapping is being created for repos. From where do I began to look for problem?</p>
  
  <pre><code>@Bean
      public RepositoryRestConfigurer repositoryRestConfigurer(){
  
          return new RepositoryRestConfigurerAdapter(){
  
              @Override
              public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config){
                  config.setBasePath("/api");
              }
          };
      }
  </code></pre>
  
  <p>following is pom.xml</p>
  
  <pre><code>&lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;springframework.version&gt;4.3.1.RELEASE&lt;/springframework.version&gt;
          &lt;springsecurity.version&gt;4.2.0.RELEASE&lt;/springsecurity.version&gt;
          &lt;hibernate.core.version&gt;4.3.11.Final&lt;/hibernate.core.version&gt;
          &lt;hibernate.validator.version&gt;5.1.3.Final&lt;/hibernate.validator.version&gt;
          &lt;mysql.connector.version&gt;5.1.31&lt;/mysql.connector.version&gt;
          &lt;postgresql.version&gt;9.4-1200-jdbc41&lt;/postgresql.version&gt;
          &lt;joda-time.version&gt;2.3&lt;/joda-time.version&gt;
          &lt;jackson-version&gt;2.7.5&lt;/jackson-version&gt;
          &lt;maven-compiler-plugin-version&gt;3.2&lt;/maven-compiler-plugin-version&gt;
          &lt;maven-war-plugin-version&gt;2.4&lt;/maven-war-plugin-version&gt;
          &lt;source-jdk&gt;1.8&lt;/source-jdk&gt;
          &lt;target-jdk&gt;1.8&lt;/target-jdk&gt;
          &lt;war-source-directory&gt;src/main/webapp&lt;/war-source-directory&gt;
          &lt;war-name&gt;dmapp&lt;/war-name&gt;
          &lt;final-name&gt;dmapp&lt;/final-name&gt;
    &lt;/properties&gt; 
  
    &lt;dependencies&gt;
      &lt;!-- Spring --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
          &lt;version&gt;${springframework.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;${springframework.version}&lt;/version&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;${springframework.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-tx&lt;/artifactId&gt;
          &lt;version&gt;${springframework.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
          &lt;version&gt;${springframework.version}&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.7.2.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
      &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
          &lt;artifactId&gt;spring-data-rest-webmvc&lt;/artifactId&gt;
          &lt;version&gt;2.6.1.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
  
  
      &lt;!--    SPRING SECURITY --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
          &lt;artifactId&gt;spring-security-web&lt;/artifactId&gt;
          &lt;version&gt;${springsecurity.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
          &lt;artifactId&gt;spring-security-config&lt;/artifactId&gt;
          &lt;version&gt;${springsecurity.version}&lt;/version&gt;
      &lt;/dependency&gt;
  
  
      &lt;!-- Hibernate --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
          &lt;version&gt;${hibernate.core.version}&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.3.11.Final&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- jsr303 validation --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.validation&lt;/groupId&gt;
          &lt;artifactId&gt;validation-api&lt;/artifactId&gt;
          &lt;version&gt;1.1.0.Final&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;
          &lt;version&gt;${hibernate.validator.version}&lt;/version&gt;
      &lt;/dependency&gt;
  
  
  
      &lt;!--  Javax Transactions --&gt;    
      &lt;dependency&gt;
          &lt;groupId&gt;javax.transaction&lt;/groupId&gt;
          &lt;artifactId&gt;jta&lt;/artifactId&gt;
          &lt;version&gt;1.1&lt;/version&gt;  
      &lt;/dependency&gt;
  
  
  
  
      &lt;!-- POSTGRESQL --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.postgresql&lt;/groupId&gt;
          &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
          &lt;version&gt;${postgresql.version}&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Joda-Time --&gt;       
      &lt;dependency&gt;
          &lt;groupId&gt;joda-time&lt;/groupId&gt;
          &lt;artifactId&gt;joda-time&lt;/artifactId&gt;
          &lt;version&gt;${joda-time.version}&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- To map JodaTime with database type --&gt;      
      &lt;dependency&gt;
          &lt;groupId&gt;org.jadira.usertype&lt;/groupId&gt;
          &lt;artifactId&gt;usertype.core&lt;/artifactId&gt;
          &lt;version&gt;3.0.0.CR1&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Servlet+JSP+JSTL --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
          &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
          &lt;version&gt;3.1.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet.jsp&lt;/groupId&gt;
          &lt;artifactId&gt;javax.servlet.jsp-api&lt;/artifactId&gt;
          &lt;version&gt;2.3.1&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
          &lt;artifactId&gt;jstl&lt;/artifactId&gt;
          &lt;version&gt;1.2&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- &lt;dependency&gt;
          &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
          &lt;artifactId&gt;jackson-core&lt;/artifactId&gt;
          &lt;version&gt;${jackson-version}&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
          &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
          &lt;version&gt;${jackson-version}&lt;/version&gt;
      &lt;/dependency&gt; --&gt;
  
    &lt;/dependencies&gt;
  
    &lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
              &lt;version&gt;${maven-compiler-plugin-version}&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;source&gt;${source-jdk}&lt;/source&gt;
                  &lt;target&gt;${target-jdk}&lt;/target&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
  
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
              &lt;version&gt;${maven-war-plugin-version}&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;warSourceDirectory&gt;${war-source-directory}&lt;/warSourceDirectory&gt;
                  &lt;warName&gt;${war-name}&lt;/warName&gt;
                  &lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
      &lt;finalName&gt;${final-name}&lt;/finalName&gt;
    &lt;/build&gt;
  </code></pre>
  
  <p>AppConfig.java</p>
  
  <pre><code>package com.pdma.dmapp.configuration;
  @Configuration
  @EnableWebMvc
  @ComponentScan(basePackages = "com.pdma.dmapp")
  public class AppConfig extends WebMvcConfigurerAdapter{
  
      @Bean(name="multipartResolver")
      public StandardServletMultipartResolver resolver(){
          return new StandardServletMultipartResolver();
      }
  
      @Override
      public void configureViewResolvers(ViewResolverRegistry registry){
          InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
          viewResolver.setViewClass(JstlView.class);
          viewResolver.setPrefix("/WEB-INF/views/");
          viewResolver.setSuffix(".jsp");
          registry.viewResolver(viewResolver);
      }
  
      @Override
      public void addResourceHandlers(ResourceHandlerRegistry registry){
          registry.addResourceHandler("/webResources/**").addResourceLocations("/webResources/");
          registry.addResourceHandler("/app/**").addResourceLocations("/app/");
      }
  }
  </code></pre>
  
  <p>PersistenceContext.java</p>
  
  <pre><code>package com.pdma.dmapp.configuration;
  
  @Configuration
  @EnableTransactionManagement
  @PropertySource(value = {"classpath:db.properties"})
  @EnableJpaRepositories("com.pdma.dmapp.module")
  public class PersistenceContext {
  
      @Autowired
      private Environment environment;
  
  
      @Bean
      @Autowired
      public LocalSessionFactoryBean sessionFactory(){
  
          LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
          sessionFactory.setDataSource(dataSource());
          sessionFactory.setPackagesToScan(new String [] {"com.pdma.dmapp.module"});
          sessionFactory.setHibernateProperties(hibernateProperties());
          return sessionFactory;
      }
  
      @Bean
      @Autowired
      LocalContainerEntityManagerFactoryBean entityManagerFactory(
              DataSource dataSource,
              Environment env){
  
          LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = 
                  new LocalContainerEntityManagerFactoryBean();
  
          entityManagerFactoryBean.setDataSource(dataSource);
          entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
          entityManagerFactoryBean.setPackagesToScan(new String [] {"com.pdma.dmapp.module"});
  
          entityManagerFactoryBean.setJpaProperties(hibernateProperties());
  
          return entityManagerFactoryBean;
  
      }
  
      @Bean
      public DataSource dataSource(){
  
          DriverManagerDataSource dataSource = new DriverManagerDataSource();
          dataSource.setDriverClassName(  environment.getRequiredProperty("jdbc.driverClassName"));
          dataSource.setUrl(              environment.getRequiredProperty("jdbc.url"));
          dataSource.setUsername(         environment.getRequiredProperty("jdbc.username"));
          dataSource.setPassword(         environment.getRequiredProperty("jdbc.password"));
          return dataSource;
      }
  
      private Properties hibernateProperties(){
  
          Properties properties = new Properties();
          properties.put("hibernate.dialect",     environment.getRequiredProperty("hibernate.dialect"));
          properties.put("hibernate.show_sql",    environment.getRequiredProperty("hibernate.show_sql"));
          properties.put("hibernate.format_sql",  environment.getRequiredProperty("hibernate.format_sql"));
          return properties;
      }
  
      @Bean
      @Autowired
      public HibernateTransactionManager hibernateTXManager(SessionFactory sessionFactory){
  
          HibernateTransactionManager txManager = new HibernateTransactionManager();
          txManager.setSessionFactory(sessionFactory);    
          return txManager;
      }
  
      @Bean
      @Autowired
      JpaTransactionManager jpaTXManager(EntityManagerFactory entityManagerFactory){
  
          JpaTransactionManager txManager = new JpaTransactionManager();
          txManager.setEntityManagerFactory(entityManagerFactory);
          return txManager;
      }
  
  
      /*  Same Bean Created as above because CrudRepository Methods are annotated with @Transactional
       *  So they require a bean named transactionManager*/
  
      @Bean
      @Autowired
      JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory){
  
          JpaTransactionManager txManager = new JpaTransactionManager();
          txManager.setEntityManagerFactory(entityManagerFactory);
          return txManager;
      }
  
      @Bean
      @Autowired
      public RepositoryRestConfigurer repositoryRestConfigurer(){
  
          return new RepositoryRestConfigurerAdapter(){
  
              @Override
              public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config){
                  config.setBasePath("/api");
              }
          };
      }
  }
  </code></pre>
  
  <p>SecurityConfiguration.java</p>
  
  <pre><code>package com.pdma.dmapp.configuration;
  
  @Configuration
  @EnableWebSecurity
  public class SecurityConfiguration extends WebSecurityConfigurerAdapter{
  
      @Autowired
      public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception
      {
          auth.inMemoryAuthentication()
          .withUser("Admin")
          .password("admin123")
          .roles("Admin");
      }
  
      @Override
      public void configure(HttpSecurity http) throws Exception
      {
          http.authorizeRequests()
          .antMatchers("/login","/webResources/**").permitAll()
              .antMatchers("/**").access("hasRole('Admin')")
              .and().formLogin()
                    .loginPage("/login")
                    .usernameParameter("username")
                    .passwordParameter("password")
              .and().csrf()
              .and().exceptionHandling().accessDeniedPage("/accessDenied");
  
          http.sessionManagement()
              .maximumSessions(1)
              .expiredUrl("/login.html");
      }
  }
  </code></pre>
  
  <p>AppInitializer.java</p>
  
  <pre><code>package com.pdma.dmapp.configuration;
  
  public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer{
  
      private static final String LOCATION = "D:/uploads/";
      private static final long MAX_FILE_SIZE = 1024*1024*200;
      private static final long MAX_REQUEST_SIZE = 1024*1024*200;
      private static final int FILE_SIZE_THRESHOLD = 0;
  
      @Override
      protected Class&lt;?&gt;[] getRootConfigClasses() {
          // TODO Auto-generated method stub
          return new Class [] {AppConfig.class, PersistenceContext.class, SecurityConfiguration.class};
      }
  
      @Override
      protected Class&lt;?&gt;[] getServletConfigClasses() {
          // TODO Auto-generated method stub
          return null;
      }
  
      @Override
      protected String[] getServletMappings() {
          // TODO Auto-generated method stub
          return new String [] {"/"};
      }
  
      @Override
      protected void customizeRegistration(ServletRegistration.Dynamic registration){
          registration.setMultipartConfig(getMultipartConfigElement());
      }
  
      private MultipartConfigElement getMultipartConfigElement(){
          MultipartConfigElement element = new MultipartConfigElement(LOCATION,
                                                                      MAX_FILE_SIZE,
                                                                      MAX_REQUEST_SIZE,
                                                                      FILE_SIZE_THRESHOLD);
          return element;
      }
  
  
       @Override
      public void onStartup(ServletContext servletContext) throws ServletException {
          super.onStartup(servletContext);
          servletContext.addListener(new SessionListener());
      }
  }
  </code></pre>
  
  <p>Repository</p>
  
  <pre><code>package com.pdma.dmapp.module.surveys.repo;
  
  @Transactional("jpaTXManager")
  @RepositoryRestResource(exported = true)
  public interface SurveyorRepo extends CrudRepository&lt;Surveyor, Integer&gt; {
  
      Surveyor findByDeviceImeiNo1OrDeviceImeiNo2(String deviceImeiNo1, String deviceImeiNo2);
      List&lt;Surveyor&gt; findByDistrictDistrictId(Integer districtId);
  }
  </code></pre>