Spring Boot 1.5.9和嵌入式jetty服务器在运行时抛出空指针异常?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring Boot 1.5.9和嵌入式jetty服务器在运行时抛出空指针异常?相关的知识,希望对你有一定的参考价值。

我正在将我们的spring boot应用程序更新为1.5.9并且我遇到了以下运行时(nullpointerexception并嵌入了jetty服务器:

Caused by: java.lang.NullPointerException
    at org.springframework.web.filter.GenericFilterBean.init(GenericFilterBean.java:207) ~[spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.eclipse.jetty.servlet.FilterHolder.initialize(FilterHolder.java:139) ~[jetty-servlet-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.sNullPointerExceptionervlet.ServletHandler.initialize(ServletHandler.java:741) ~[jetty-servlet-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.springframework.boot.context.embedded.jetty.JettyEmbeddedWebAppContext$JettyEmbeddedServletHandler.deferredInitialize(JettyEmbeddedWebAppContext.java:46) ~[spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
    at org.springframework.boot.context.embedded.jetty.JettyEmbeddedWebAppContext.deferredInitialize(JettyEmbeddedWebAppContext.java:36) ~[spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
    at org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainer.handleDeferredInitialize(JettyEmbeddedServletContainer.java:205) ~[spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
    at org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainer.handleDeferredInitialize(JettyEmbeddedServletContainer.java:211) ~[spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
    at org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainer.start(JettyEmbeddedServletContainer.java:138) ~[spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]

它在spring boot 1.4.0下运行良好,所以问题肯定与升级到1.5.9有关?

我在pom.xml中有以下内容:

<dependency>                                                                     
        <groupId>org.springframework.boot</groupId>                                  
        <artifactId>spring-boot-starter-web</artifactId>                             
        <version>1.5.9.RELEASE</version>                                    
        <exclusions>                                                                 
            <exclusion>                                                              
                <groupId>org.springframework.boot</groupId>                          
                <artifactId>spring-boot-starter-tomcat</artifactId>                  
            </exclusion>                                                             
        </exclusions>                                                                
    </dependency>                                                                    
    <dependency>                                                                     
        <groupId>org.springframework.boot</groupId>                                  
        <artifactId>spring-boot-starter-jetty</artifactId>                           
      <version>1.5.9.RELEASE</version>                                    
    </dependency>

谢谢

答案

这对我来说工作正常,你可以删除你的缓存(.m2文件夹)尝试再次构建项目可能是缓存问题

这是我的POM

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

<groupId>com.stackflow.test</groupId>
<artifactId>DemoSpring1.5.9</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>DemoSpring1.5.9</name>
<description>Stackflow project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.9.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jetty</artifactId>
    </dependency>


    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

以上是关于Spring Boot 1.5.9和嵌入式jetty服务器在运行时抛出空指针异常?的主要内容,如果未能解决你的问题,请参考以下文章

Spring Boot上传文件

Spring Boot上传文件

Spring Boot上传文件

Spring Boot上传文件

Spring Boot上传文件

springboot 嵌入式Servlet容器自动配置原理和容器启动原理