2017-01-09 14 views
0

私はジャージ+スプリングの統合を試みています。ジャージ+スプリング統合とweb.xml

私はweb.xml構成に関する質問があります。

<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が含まれていません。

この例では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-)2つのweb.xml設定の主な違いは何ですか?

2)なぜ2番目の例がResourceConfigを拡張してRequestContextFilter.classを登録するのですか?

答えて

0

ジャージーServletContainer(この場合はSpringServlet)は、複数の方法で初期化することができます。..

最初の例だけで、それは簡単な例ですので、必要なリソースを探すためにパッケージを登録します。

複数の設定を定義する必要がある場合は、ServletProperties.JAXRS_APPLICATION_CLASSという名前のinitパラメータを使用して、Applicationを実装するクラスを参照することができます。

このアプリケーションインスタンス(org.glassfish.jersey.examples.helloworld.spring.MyApplication)は、マッパーやフィルタなどのすべてのサーブレットレベルの設定を定義できます。