JAX-RS REST服务作为库

时间:2010-11-11 19:19:48

标签: java rest jersey jax-rs

是否可以将我的其余资源类打包到.jar库中,以便当它们包含在应用获取服务的某人应用中时?

我目前正在使用泽西(jersey.dev.java.net)

1 个答案:

答案 0 :(得分:3)

好吧,我不明白为什么它不起作用GRANTED那个人在他们的web.xml中定义了其余的servlet来从jar中找到你的REST包......就像这样: -

<servlet>
    <servlet-name>Jersey Rest Web Service</servlet-name>
    <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
    <init-param>
        <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
        <param-value>com.sun.jersey.api.core.PackagesResourceConfig</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <!--  Package that contains all Rest Web Services -->
        <param-value>com.project.your.rest.package.in.jar</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Jersey Rest Web Service</servlet-name>
    <url-pattern>/api/*</url-pattern>
</servlet-mapping>