8

我有一个 Resteasy 应用程序,它使用 Spring 并ContainerRequestFilter包含ContainerResponseFilter@Provider. 该应用程序使用3.0-beta-6的是 Resteasy 版本。

这些过滤器在添加到resteasy.providersweb.xml 中的 context 参数时按预期工作,如下所示:

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

如果我从这里删除过滤器,它们将不再被调用。

我假设这些提供者在使用org.jboss.resteasy.plugins.spring.SpringContextLoaderListener. 对我来说奇怪的是,它适用PreProcessInterceptor于以前版本的 Resteasy 中的实现,并且仍然适用于 v3,但过滤器和异常映射器不会自动注册。

问题

  1. resteasy.providers如果类是@Provider用 Spring 注释和扫描的,为什么需要 context 参数?
  2. 是否有在运行时设置这些提供程序的编程方式?
4

1 回答 1

8

为了让 Spring 扫描提供程序,我必须在我的 Spring Java 配置类中添加includeFilters参数。@ComponentScan

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

您也可以只注释它们,@ComponentSpring@Provider将确保它们在使用 Resteasy 时被 Resteasy 检测到SpringContextLoaderListener

于 2013-07-01T06:46:18.647 回答