0

I am trying to use JerseyConfig class in existing sping boot application but for some reason when I add this configuration:

    @Component
    public class JerseyConfig extends ResourceConfig  {
    public JerseyConfig() {
         register(Users.class);
         register(Groups.class);
         property("SCIM_IMPLEMENTATION_INSTANCE", new JerseyApplication());
      }
    }

The @RestController endpoints do not work as expexted anymore. All of them return 404 after applying this JerseyConfig class. All of the Jersey endpoints work fine.

Can I use JAX rs endpoints (in my case I use Jersey) and @RestCotroller in the same application? I need some configuration for separating my existing REST servcices from the new JAX rs endpoints. If anybody can help I will really appreciate it. Thank you!

skywalker
  • 696
  • 2
  • 16
  • 37

1 Answers1

0

There is a workaround for combining Jersey resources and Spring controllers. There are a couple of changes that you will need to do to your setup.

  1. Change annotation of JerseyConfig from @Component to @Configuration and add package of your controllers to scan

    // scan the resources package for your resources / restControler public JerseyConfig() { // other code packages(package_of_your_rest_controller); }

  2. Change annotation of your rest controller from @ReuestMapping to @Path E.g. if your controller is like this:

    @RestController @Component public class MyRestController {

    @RequestMapping("/foo")
    public String foo() {
        return "foo";
    }
    

    }

    It becomes this:

    @Path("/") @Component public class MyRestController {

    @Path("/foo")
    public String foo() {
        return "foo";
    }
    

    }

Give this a try once if you can.

tryingToLearn
  • 10,691
  • 12
  • 80
  • 114
  • 1
    Hello :) thanks for your answer! The thing I did is adding `@ApplicationPath("/path")` to `ResourceConfig` class and it worked fine! – skywalker Aug 16 '19 at 08:49