处理ContextClosedEvent的ApplicationListener的NullPointer警告

时间:2017-05-11 20:11:11

标签: java spring spring-boot cxf

我有一个Spring Boot Apache CXF Web应用程序。它运行得很好。但是每当我关闭应用程序时,我都会从处理ContextClosedEvent的ApplicationListener获得有关nullpointer的警告。看起来它可能与Apache CXF总线有关。

11:10:24.728 INFO  [Thread-10][AnnotationConfigEmbeddedWebApplicationContext] Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@39b667c3: startup date [Thu May 11 11:09:48 PDT 2017]; root of context hierarchy
11:10:24.738 WARN  [Thread-10][AnnotationConfigEmbeddedWebApplicationContext] Exception thrown from ApplicationListener handling ContextClosedEvent
java.lang.NullPointerException: null
    at java.util.concurrent.ConcurrentHashMap.replaceNode(ConcurrentHashMap.java:1106)
    at java.util.concurrent.ConcurrentHashMap.remove(ConcurrentHashMap.java:1097)
    at org.apache.cxf.transport.http.DestinationRegistryImpl.removeDestination(DestinationRegistryImpl.java:63)
    at org.apache.cxf.transport.http.AbstractHTTPDestination.deactivate(AbstractHTTPDestination.java:961)
    at org.apache.cxf.transport.AbstractObservable.setMessageObserver(AbstractObservable.java:65)
    at org.apache.cxf.endpoint.ServerImpl.stop(ServerImpl.java:174)
    at org.apache.cxf.endpoint.ServerImpl.destroy(ServerImpl.java:180)
    at org.apache.cxf.bus.managers.ServerRegistryImpl.preShutdown(ServerRegistryImpl.java:90)
    at org.apache.cxf.bus.managers.CXFBusLifeCycleManager.preShutdown(CXFBusLifeCycleManager.java:97)
    at org.apache.cxf.bus.extension.ExtensionManagerBus.shutdown(ExtensionManagerBus.java:326)
    at org.apache.cxf.bus.extension.ExtensionManagerBus.shutdown(ExtensionManagerBus.java:313)
    at org.apache.cxf.bus.spring.SpringBus.onApplicationEvent(SpringBus.java:109)
    at org.apache.cxf.bus.spring.SpringBus$1.onApplicationEvent(SpringBus.java:58)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:166)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:382)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:336)
    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:989)
    at org.springframework.context.support.AbstractApplicationContext$2.run(AbstractApplicationContext.java:923)
11:10:24.780 INFO  [Thread-10][AnnotationMBeanExporter] Unregistering JMX-exposed beans on shutdown

这是我写的一个课程,我认为错误可能源于此,但我不确定。

import javax.xml.ws.Endpoint;
import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;


@Configuration
public class EndpointConfig {

    @Autowired
    private Bus bus;

    @Autowired
    private AmazonS3 s3client;

    @Bean
    public Endpoint endpoint() {
      EndpointImpl endpoint = new EndpointImpl(bus,
            new AcmeWebServiceImpl(s3client));
      endpoint.publish();
      return endpoint;
  }

  @Bean 
  public AmazonS3 amazonS3(){
     AmazonS3 amazonS3 = AmazonS3ClientBuilder.defaultClient();
     return amazonS3;
  }
}

1 个答案:

答案 0 :(得分:2)

我发布这个作为答案,也许它也可以帮助其他人。

是的,我确实设法修复它...经过3天的尝试...它更像是一种解决方法,也许修复太多了,因为修复应该可能在cxf代码中完成...实际上我们的堆栈跟踪是一个有点不同,我在下面附上它。类似的,直到某一点,所以也许我们如何修复它可能对你有所帮助。这是:

enter image description here

我们注意到在 DestinationRegistryImpl - removeDestination 方法第63行中,从 ConcurrentHashmap 中删除的路径为null这来自一个级别 AbstractHTTPDestination.deactivate(AbstractHTTPDestination.java:965)。在我们的例子中,我们使用了一个 ServletDestination 的实例( AbstractHTTPDestination 的子代)继承受保护的变量 path ,并通过其构造函数设置了此变量(ServletDestination构造函数)在org.apache.cxf.transport.servlet.ServletDestinationFactory - #33中,其中EndpointInfo实例的地址被设置为路径。 我们所要做的就是为我们的端点设置一个地址(JAXRSServerFactoryBean),这个转换为不再为null的路径,我们摆脱了NPE。

我很抱歉它的含义,希望它有一定意义......我们有3天的调试和查看cxf框架的代码,这不是很好..

我们添加了第74行并摆脱了NPE:

enter image description here