有沒有辦法在Servlet 3.x容器中運行Jersey servlet容器(2.x)描述符作爲javax.servlet.Filter
?我要爲靜態資源旁邊我的服務,因此需要使用根據的Javadoc無描述符的澤西servlet容器作爲Servlet 3.x容器中的過濾器運行
財產只有當新澤西servlet容器被配置爲一個使用javax運行應用時,作爲一個過濾器運行
jersey.config.servlet.filter.forwardOn404
或jersey.config.servlet.filter.staticContentRegex
只工作.servlet.Filter,否則這個屬性將被忽略。
我想擺脫web.xml
完全
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>My-Webservice</display-name>
<filter>
<filter-name>Jersey Filter</filter-name>
<filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.foo.webservices.MyApplication</param-value>
</init-param>
</filter>
</web-app>
,並擁有一切在我的自定義Application
類
@ApplicationPath(value = "/")
public class MyApplication extends ResourceConfig
{
public MyApplication()
{
packages("com.foo.webservices.services");
property(ServletProperties.FILTER_FORWARD_ON_404, true);
}
}
的官方文檔(https://jersey.java.net/documentation/latest/deployment.html#deployment.servlet.3)沒有說明什麼關於過濾器不幸。
很好的答案,謝謝。我只需要在getApplicationClass方法中添加另一個檢查,因爲它錯誤地將'org.glassfish.jersey.server.ResourceConfig $ RuntimeConfig'識別爲應用程序類。我在'break'語句周圍添加了'if(applicationCls!= null && applicationCls.getAnnotation(ApplicationPath.class)!= null)'。 – lazlev