Reputation: 1315
I'm trying to make jersey+spring integration.
I have question about web.xml configuraiton.
This example includes SpringServlet:
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>
com.sun.jersey.spi.spring.container.servlet.SpringServlet
</servlet-class>
<init-param>
<param-name>
com.sun.jersey.config.property.packages
</param-name>
<param-value>com.mkyong.rest</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
https://www.mkyong.com/webservices/jax-rs/jersey-spring-integration-example/
But another example doesn't include SpringServlet.
The last example includes:
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>org.glassfish.jersey.examples.helloworld.spring.MyApplication</param-value>
</init-param>
and in MyApplication class it extends ResourceConfig and register RequestContextFilter.class.
My questions are.
1-)What is the main difference between two web.xml configuration?
2-)Why the second example extends ResourceConfig and register RequestContextFilter.class ?
Upvotes: 0
Views: 1412
Reputation: 143
A jersey ServletContainer(SpringServlet in this case) can be initialized in multiple ways..
The first example just registers the package to look for the required resource since it's a simplified example.
However in cases where you need to define multiple configurations, that can be done using an init parameter with the name ServletProperties.JAXRS_APPLICATION_CLASS that refers to a class implementing Application.
This Application instance(org.glassfish.jersey.examples.helloworld.spring.MyApplication) can define all servlet level configurations like mappers,filters etc.
Upvotes: 0