title: @RepositoryRestController custom controller with RepositoryRestMvcConfiguration and AbstractAnnotationConfigDispatcherServletInitializer
body: <p>I am trying to implement custom controller to handle method defined in custom repository to be able to expose resources using this method via REST (according to <a href="https://stackoverflow.com/questions/25201306/implementing-custom-methods-of-spring-data-repository-and-exposing-them-through?lq=1">Implementing custom methods of Spring Data repository and exposing them through REST</a>).</p>
  
  <p>Here is the configuration and other relevant code:</p>
  
  <pre><code>public class ApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
  
       @Override
       protected Class&lt;?&gt;[] getRootConfigClasses() {
          return new Class&lt;?&gt;[] {ApplicationConfig.class};
       }
  
       @Override
       protected Class&lt;?&gt;[] getServletConfigClasses() {
          return new Class&lt;?&gt;[] {RepositoryRestMvcConfiguration.class};
       }
  
       @Override
       protected String[] getServletMappings() {
          return new String[]{"/api/*"};
       }
  
  }
  </code></pre>
  
  <p>ApplicationConfig:</p>
  
  <pre><code>@Configuration
  @EnableJpaRepositories
  @EnableTransactionManagement
  public class ApplicationConfig {
  
      @Bean
      public DataSource dataSource() {
          // data source settings
      }
  
      @Bean
      public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
          // em factory settings
      }
  
      @Bean
      public PlatformTransactionManager transactionManager() {
          // tx mng settings
      }
  }
  </code></pre>
  
  <p>ExperimentRepository:</p>
  
  <pre><code>@RepositoryRestResource
  public interface ExperimentRepository extends PagingAndSortingRepository&lt;Experiment, Long&gt;,
      ExperimentRepositoryCustom {
  
      @RestResource(rel = "byName", path = "byName")
      Page&lt;Experiment&gt; findByNameContaining(@Param("name") String name, Pageable pageable);
  
  }
  </code></pre>
  
  <p>ExperimentRepositoryCustom:</p>
  
  <pre><code>public interface ExperimentRepositoryCustom {
  
      Page&lt;Experiment&gt; findUsingCustomFilter(...);
  
  }
  </code></pre>
  
  <p>ExperimentRepositoryImpl:</p>
  
  <pre><code>public class ExperimentRepositoryImpl implements ExperimentRepositoryCustom {
  
      @Override
      public Page&lt;Experiment&gt; findUsingCustomFilter(...) {
          // search for experiment based on given filter
      }
  
  }
  </code></pre>
  
  <p>ExperimentController:</p>
  
  <pre><code>@RepositoryRestController
  public class ExperimentController {
  
      @Autowired
      private ExperimentRepository experimentRepository;
  
  
      @RequestMapping(value = "/experiments/search/findByFilter", method= RequestMethod.GET)
      @ResponseBody
      public ResponseEntity&lt;Experiment&gt; searchUsingFilter(@RequestParam Long id) {
          // for test purpose call method from CrudRepository (will be replaced by findUsingCustomFilter(...)) 
          return new ResponseEntity(experimentRepository.findOne(id), HttpStatus.OK);
      }
  }
  </code></pre>
  
  <p>Project structure:</p>
  
  <pre><code>basepackage.model.Experiment
  basepackage.repository.ExperimentController
  basepackage.repository.ExperimentRepository
  basepackage.repository.ExperimentRepositoryImpl
  basepackage.repository.ExperimentRepositoryCustom
  basepackage.ApplicationInitializer
  basepackage.ApplicationConfig
  </code></pre>
  
  <p>All resources exposed by links automatically generated based on used Repositories are accessible with no problem but calling GET method on <a href="http://localhost:8080/app/api/experiments/search/findByFilter?id=1" rel="nofollow noreferrer">http://localhost:8080/app/api/experiments/search/findByFilter?id=1</a> ends with 404 (resources exposed by links automatically generated based on used Repositories work fine). I assume that ExperimentController is not registered in Spring container or I am missing some additional settings regarding controller method. Any suggestions? </p>
  
  <p>Thanks in advance!</p>