【问题标题】:Jersey+Spring integration and web.xmlJersey+Spring 集成和 web.xml
【发布时间】:2017-05-24 01:40:37
【问题描述】:

我正在尝试将球衣+弹簧集成。

我对 web.xml 配置有疑问。

这个例子包括 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/

但另一个例子不包括 SpringServlet。

https://github.com/jersey/jersey/blob/2.25/examples/helloworld-spring-webapp/src/main/webapp/WEB-INF/web.xml

最后一个例子包括:

    <init-param>
        <param-name>javax.ws.rs.Application</param-name>
        <param-value>org.glassfish.jersey.examples.helloworld.spring.MyApplication</param-value>
    </init-param>

在 MyApplication 类中,它扩展了 ResourceConfig 并注册了 RequestContextFilter.class。

我的问题是。

1-)两种web.xml配置的主要区别是什么?

2-)为什么第二个例子扩展了 ResourceConfig 并注册了 RequestContextFilter.class ?

【问题讨论】:

    标签: java spring rest jersey jax-rs


    【解决方案1】:

    一个 jersey ServletContainer(在这种情况下是 SpringServlet)可以通过多种方式初始化..

    第一个示例只是注册包以查找所需的资源,因为它是一个简化示例。

    但是,在您需要定义多个配置的情况下,可以使用名为 ServletProperties.JAXRS_APPLICATION_CLASS 的 init 参数来完成,该参数指的是实现 Application 的类。

    这个应用程序实例(org.glassfish.jersey.examples.helloworld.spring.MyApplication)可以定义所有servlet级别的配置,如映射器、过滤器等。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-20
      • 1970-01-01
      • 2015-01-06
      • 1970-01-01
      • 1970-01-01
      • 2016-04-24
      相关资源
      最近更新 更多