Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is resteasy.providers still required when using Spring with @Provider annotations?

I have a Resteasy application that uses Spring and contains ContainerRequestFilter and ContainerResponseFilter implementations annotated with @Provider. The application is using version 3.0-beta-6 of Resteasy.

These filters work as expected when they are added to the resteasy.providers context parameter in web.xml like so:

<context-param>
      <param-name>resteasy.providers</param-name>
      <param-value>foo.filter.LoggingRequestFilter,
                   foo.filter.LoggingResponseFilter</paramvalue>
</context-param> 

If I remove the filters from here they are no longer called.

I was assuming that these providers would automatically register with Resteasy when using org.jboss.resteasy.plugins.spring.SpringContextLoaderListener. The strange thing to me is that it worked for PreProcessInterceptor implementations in previous versions of Resteasy, and still works in v3, but Filters and ExceptionMappers do not auto-register.

Questions

  1. Why is the resteasy.providers context parameter necessary if the classes are annotated with @Provider and scanned by Spring?
  2. Is there a programmatic way to set these providers at runtime?
like image 208
gregwhitaker Avatar asked Jun 03 '13 08:06

gregwhitaker


1 Answers

In order to get the providers scanned by Spring I had to add the includeFilters parameter to @ComponentScan on my Spring Java configuration class.

@ComponentScan(value = "com.foo", 
               includeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION, value = Provider.class))

You can also just annotate them with @Component along with @Provider and Spring will make sure they get detected by Resteasy when using Resteasy's SpringContextLoaderListener.

like image 104
gregwhitaker Avatar answered Oct 15 '22 21:10

gregwhitaker