title: Katharsis in combination with Spring Boot
body: <p>I have implemented a REST API using Spring Boot (version 1.3.6.RELEASE), which is working as expected. However I would like to add JSON API support to my application.</p>
  
  <p>The problem is that I get a 404 when trying to execute a GET on a Katharsis resource.</p>
  
  <p>The dependencies in pom.xml look as follows (I use Spring Security too):</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;exclusions&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-starter-tomcat&lt;/artifactId&gt;
              &lt;/exclusion&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;org.hsqldb&lt;/groupId&gt;
                  &lt;artifactId&gt;hsqldb&lt;/artifactId&gt;
              &lt;/exclusion&gt;
          &lt;/exclusions&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-tomcat&lt;/artifactId&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-integration&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.integration&lt;/groupId&gt;
          &lt;artifactId&gt;spring-integration-jdbc&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
          &lt;artifactId&gt;spring-security-web&lt;/artifactId&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;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-hateoas&lt;/artifactId&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;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.codehaus.woodstox&lt;/groupId&gt;
          &lt;artifactId&gt;woodstox-core-asl&lt;/artifactId&gt;
          &lt;version&gt;4.4.1&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;net.sf.ehcache&lt;/groupId&gt;
          &lt;artifactId&gt;ehcache&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hsqldb&lt;/groupId&gt;
          &lt;artifactId&gt;hsqldb&lt;/artifactId&gt;
          &lt;version&gt;${hsqldb.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!--SpringFox dependencies --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;io.springfox&lt;/groupId&gt;
          &lt;artifactId&gt;springfox-swagger2&lt;/artifactId&gt;
          &lt;version&gt;${springfox-version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;io.springfox&lt;/groupId&gt;
          &lt;artifactId&gt;springfox-swagger-ui&lt;/artifactId&gt;
          &lt;version&gt;${springfox-version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-context-support&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.sun.mail&lt;/groupId&gt;
          &lt;artifactId&gt;javax.mail&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.velocity&lt;/groupId&gt;
          &lt;artifactId&gt;velocity&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.velocity&lt;/groupId&gt;
          &lt;artifactId&gt;velocity-tools&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;dumbster&lt;/groupId&gt;
          &lt;artifactId&gt;dumbster&lt;/artifactId&gt;
          &lt;version&gt;1.6&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
          &lt;exclusions&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;javax.mail&lt;/groupId&gt;
                  &lt;artifactId&gt;mail&lt;/artifactId&gt;
              &lt;/exclusion&gt;
          &lt;/exclusions&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;io.katharsis&lt;/groupId&gt;
          &lt;artifactId&gt;katharsis-spring&lt;/artifactId&gt;
          &lt;version&gt;2.6.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.reflections&lt;/groupId&gt;
          &lt;artifactId&gt;reflections&lt;/artifactId&gt;
          &lt;version&gt;0.9.9&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p>My application initialisation class is as follows:</p>
  
  
  
  <pre class="lang-java prettyprint-override"><code>@SpringBootApplication
  @Configuration
  @EnableAutoConfiguration(exclude = WebMvcAutoConfiguration.class)
  @EnableSwagger2
  @ComponentScan(basePackages = "com.myapp")
  @Import({KatharsisConfigV2.class})
  public class Application {
      public static void main(String[] args) {
          ApplicationContext ctx = SpringApplication.run(Application.class, args);
      }
  }
  </code></pre>
  
  <p>The resource class:</p>
  
  <pre class="lang-java prettyprint-override"><code>@ApiModel(description = "")
  @JsonApiResource(type = "foo-data")
  public class FooData extends DomainRepresentation {
      @JsonApiId
      private String id = null;
      @JsonProperty
      private String name = null;
      // .... getters &amp; setters
  }
  </code></pre>
  
  <p>ResourceRepository class:</p>
  
  <pre class="lang-java prettyprint-override"><code>@JsonApiResourceRepository(FooData.class)
  @Component
  public class FooDataKatApi extends MyApi {
      @Autowired
      private FooDataService fooDataService;
  
      @JsonApiFindOne
      public FooData foodataIdGet(String id, QueryParams requestParams) { 
          FooData result = fooDataService.getFooDataById(id);
          return result;
      }
  }
  </code></pre>
  
  <p>If I add Spring <code>@ResourceMapping</code>s than I get data back but without Katharsis additions like "link", etc. It's as if the API call is not being picked up by Katharsis, but it's handled by Spring.</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>-- EDITTED --</p>
  
  <p>The FooDataService is as follows:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Service
  public class FooDataService extends MyService {
      @Autowired
      private FooDataRepository fooDataRepository;
  
      public FooData getFooDataById(String id) {
          FooDataEnt fooDataEnt = fooDataRepository.findByFooDataId(id);
  
          if (fooDataEnt != null) {
              return convertFooDataEntToFooData.apply(fooDataEnt);
          }
  
          throw new NotFoundException("Foo not found");
      }
  }
  </code></pre>
  
  <p>The FooDataRepository extends Spring's PagingAndSortingRepository.</p>
  
  <p>Katharsis config in application.yaml:</p>
  
  <pre class="lang-java prettyprint-override"><code>katharsis:
      resourcePackage: com.my.package
      domainName: http://localhost:8080
      pathPrefix: /api/kat
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/wtUF0.png" rel="nofollow">The request and response from PostMan</a></p>
  
  <p>-- UPDATE 1 --</p>
  
  <p>Apparently the configured value for katharsis.pathPrefix was not correct. Web application's context-root is "/api" and the value of katharsis.pathPrefix should be only "/kat".</p>
  
  <p>My next problem is that a RepositoryNotFoundException is being throw while handling the request, while the Resource class is found already.</p>