2

I want to use Spring boot with JAX-RS (Jersey Implementation). If we were not using Spring Boot, we could use the following code to register all the Rest service classes

@ApplicationPath("/myrest") public class MyApplication extends Application { @Override public Set<Class<?>> getClasses() { Set<Class<?>> s = new HashSet<Class<?>>(); s.add(HelloWorld.class); return s; } } 

This works fine in a Servlet 3.0 supported container.

But when we use Spring Boot with JAX-RS(Jersey) why do we have to extend from org.glassfish.jersey.server.ResourceConfig Why extending from javax.ws.rs.core.Application doesn't work?

1
  • when you use Jersey as a 'standalone' service, you put Jersey's entry point servlet in the web.xml file. This way, Jersey is able to set up dependency injection and other features. When you use Spring boot you have to comply with the way Spring does its configuration, and in this particular case you have to extend ResourceConfig and annotate your config class with @Component, otherwise Spring won't know about your services. Commented Mar 16, 2016 at 13:34

1 Answer 1

4

But when we use Spring Boot with JAX-RS(Jersey) why do we have to extend from org.glassfish.jersey.server.ResourceConfig Why extending from javax.ws.rs.core.Application doesn't work?

Because Spring Boot uses the ResourceConfig type as the as a service that it injects into its auto configurer, namely the JerseyAutoConfiguration. If you look at the source code, you will see

@Autowired private ResourceConfig config; 

From there, Sprig Boot configures the app with that instance. If a ResourceConfig bean is not available in the Spring context, then not auto-configuration happens.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.