如何爲servlet的<init-param>
標籤下的給定<param-name>
指定多個<param-value>
。以下是我的web.xml文件:如何在使用Jersey的REST Web服務中爲服務類指定多個軟件包名稱
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>com.vogella.jersey.first</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<!-- Register resources and providers under com.vogella.jersey.first package. -->
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.vogella.jersey.first</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
參數jersey.config.server.provider.packages定義了包澤西將查找Web服務類。
我想在這裏指定多個包名,因爲我的服務類位於不同的包中。喜歡的東西下面,但他們沒有工作:
1)多<param-value>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.vogella.jersey.first</param-value>
<param-value>com.vogella.jersey.second</param-value>
</init-param>
2)多<init-param>
<servlet>
...
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.vogella.jersey.first</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.vogella.jersey.second</param-value>
</init-param>
我該怎麼辦呢?
僅供參考,掃描是遞歸的。即'com.vogella.jersey'將掃描上述兩個包 –