2016-08-21 228 views
1

無法從澤西島2.22.1版本升級到版本2.22.2。
層次:
遷移澤西島2.22.1到澤西島2.22.2

def jerseyVersion = '2.22.1' 
def hk2Version = '2.4.0-b31' 
def giuceVersion = '4.0' 

dependencies { 
    //javax 
    compile "javax.servlet:javax.servlet-api:3.1.0" 
    //jersey 
    compile "org.glassfish.jersey.core:jersey-server:${jerseyVersion}" 
    compile "org.glassfish.jersey.containers:jersey-container-servlet:${jerseyVersion}" 
    //hk2 
    compile "org.glassfish.hk2:guice-bridge:${hk2Version}" 
    //guice 
    compile "com.google.inject:guice:${giuceVersion}" 
    compile "com.google.inject.extensions:guice-servlet:${giuceVersion}" 
} 

文件的web.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 

    <display-name>REST API App</display-name> 

    <listener> 
     <listener-class>com.example.core.JerseyGuiceServletContextListener</listener-class> 
    </listener> 

    <filter> 
     <filter-name>guiceFilter</filter-name> 
     <filter-class>com.google.inject.servlet.GuiceFilter</filter-class> 
    </filter> 

    <filter-mapping> 
     <filter-name>guiceFilter</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 

</web-app> 

類JerseyGuiceServletContextListener:

從的build.gradle
enter image description here
Dependencies部分10

類JerseyServletModuleConfig:

package com.example.core; 

import com.google.inject.Scopes; 
import com.google.inject.servlet.ServletModule; 
import com.example.ws.HeyResource; 
import org.glassfish.jersey.servlet.ServletContainer; 

import java.util.Map; 
import java.util.TreeMap; 

class JerseyServletModuleConfig extends ServletModule { 
    @Override 
    protected void configureServlets() { 
     Map<String, String> servletContainerParams = new TreeMap<>(); 
     servletContainerParams.put("javax.ws.rs.Application", JerseyConfiguration.class.getCanonicalName()); 
     bind(ServletContainer.class).in(Scopes.SINGLETON); 
     filter("/*").through(ServletContainer.class, servletContainerParams); 
     bind(HeyResource.class).in(Scopes.SINGLETON); 
    } 
} 

類JerseyConfiguration:

package com.example.core; 

import com.google.inject.Injector; 
import org.glassfish.hk2.api.ServiceLocator; 
import org.glassfish.jersey.server.ResourceConfig; 
import org.jvnet.hk2.guice.bridge.api.GuiceBridge; 
import org.jvnet.hk2.guice.bridge.api.GuiceIntoHK2Bridge; 

import javax.inject.Inject; 
import javax.servlet.ServletContext; 

class JerseyConfiguration extends ResourceConfig { 
    @Inject 
    public JerseyConfiguration(ServiceLocator serviceLocator, ServletContext servletContext) { 
     packages("com.example.ws"); 
     GuiceBridge.getGuiceBridge().initializeGuiceBridge(serviceLocator); 
     GuiceIntoHK2Bridge guiceBridge = serviceLocator.getService(GuiceIntoHK2Bridge.class); 
     guiceBridge.bridgeGuiceInjector((Injector) servletContext.getAttribute(Injector.class.getName())); 
    } 
} 

在版本2.22.1新澤西一切完美。當我更改2.22.2的版本 - 我異常:

21 - 8 - 12 2016:34:12.577嚴重[本地主機 - startStop-1] org.apache.catalina.core .StandardContext.filterStart異常 開始濾波器guiceFilter顯示java.lang.NullPointerException在 org.glassfish.jersey.servlet.init.FilterUrlMappingsProviderImpl.getFilterUrlMappings(FilterUrlMappingsProviderImpl.java:66) 在 org.glassfish.jersey.servlet.ServletContainer.init (ServletContainer.java:444)

我認爲它可以在guice-bridge版本中涵蓋的問題。我用版本2.4.0-b34(用於org.glassfish.jersey.core:jersey-server的各種hk2依賴)替換了版本2.4.0-b31 - 沒有幫助。

鏈接到類FilterUrlMappingsProviderImpl:https://github.com/jersey/jersey/blob/79d7767be5102f57520cf23900cad3a7ef4230ad/containers/jersey-servlet/src/main/java/org/glassfish/jersey/servlet/init/FilterUrlMappingsProviderImpl.java

從上述類FilterUrlMappingsProviderImpl鏈路變得清晰,這是不可能得到一個FilterRegistration類對象。

存在什麼問題?你可以爲她的決定提供什麼建議? 謝謝。

回答

0

解決方案


文件的web.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 

    <display-name>REST API App</display-name> 

    <listener> 
     <listener-class>com.example.core.JerseyGuiceServletContextListener</listener-class> 
    </listener> 

    <filter> 
     <filter-name>guiceFilter</filter-name> 
     <filter-class>com.google.inject.servlet.GuiceFilter</filter-class> 
    </filter> 

    <filter-mapping> 
     <filter-name>guiceFilter</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 

    <filter> 
     <filter-name>jerseyFilter</filter-name> 
     <filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class> 
     <init-param> 
      <param-name>javax.ws.rs.Application</param-name> 
      <param-value>com.example.core.JerseyConfiguration</param-value> 
     </init-param> 
    </filter> 
    <filter-mapping> 
     <filter-name>jerseyFilter</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 

</web-app> 

類JerseyServletModuleConfig:

package com.example.core; 

import com.google.inject.Scopes; 
import com.google.inject.servlet.ServletModule; 
import com.example.ws.HeyResource; 
import org.glassfish.jersey.servlet.ServletContainer; 

import java.util.Map; 
import java.util.TreeMap; 

class JerseyServletModuleConfig extends ServletModule { 
    @Override 
    protected void configureServlets() { 
     bind(HeyResource.class).in(Scopes.SINGLETON); 
    } 
}