Spring boot webflux应用程序不会启动IllegalStateException

时间:2017-06-16 13:39:56

标签: java spring spring-boot illegalstateexception spring-webflux

这是我的build.gradle

buildscript {
    ext {
        springBootVersion = '2.0.0.M2'
    }
    repositories {
        mavenCentral()
        jcenter()
        maven { url "https://repo.spring.io/snapshot" }
        maven { url "https://repo.spring.io/milestone" }
    }
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
    }
}

apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
    jcenter()
    maven { url "https://repo.spring.io/snapshot" }
    maven { url "https://repo.spring.io/milestone" }
}

dependencies {
    compile 'org.springframework.boot:spring-boot-starter-security',
            'org.springframework.boot:spring-boot-starter-mail',
            'org.springframework.boot:spring-boot-starter-validation',
            'org.springframework.boot:spring-boot-starter-webflux',
            // support libs
            'commons-io:commons-io:2.5',
            'commons-codec:commons-codec:1.10',
            'org.apache.commons:commons-lang3:3.4',
            'org.apache.commons:commons-collections4:4.1',
            //validation
            'javax.validation:validation-api:1.1.0.Final'
    compileOnly 'org.springframework.boot:spring-boot-configuration-processor',
            'org.projectlombok:lombok'
    testCompile 'org.springframework.boot:spring-boot-starter-test'
}

当我尝试运行应用程序时,它失败了java.lang.IllegalStateException: java.lang.NullPointerException
Stacktrace:

java.lang.IllegalStateException: java.lang.NullPointerException
    at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.stopAndReleaseReactiveWebServer(ReactiveWebServerApplicationContext.java:152) ~[spring-boot-2.0.0.M2.jar:2.0.0.M2]
    at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:52) ~[spring-boot-2.0.0.M2.jar:2.0.0.M2]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.0.0.M2.jar:2.0.0.M2]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386) [spring-boot-2.0.0.M2.jar:2.0.0.M2]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.0.M2.jar:2.0.0.M2]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1245) [spring-boot-2.0.0.M2.jar:2.0.0.M2]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1233) [spring-boot-2.0.0.M2.jar:2.0.0.M2]
    at com.getcredit.bankscraper.Application.main(Application.java:10) [main/:na]
Caused by: java.lang.NullPointerException: null
    at org.springframework.boot.web.embedded.netty.NettyWebServer.stop(NettyWebServer.java:113) ~[spring-boot-2.0.0.M2.jar:2.0.0.M2]
    at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.stopAndReleaseReactiveWebServer(ReactiveWebServerApplicationContext.java:148) ~[spring-boot-2.0.0.M2.jar:2.0.0.M2]
    ... 7 common frames omitted

项目是通过start.spring.io网站生成的。

1 个答案:

答案 0 :(得分:1)

经过一些测试,我发现了我的问题。这是使用@PostConstruct注释的bean的init方法中的NPE异常。您可以像这样重现此问题:

@Component
class Test {

    String str;

    @PostConstruct
    private void init() {
        System.out.println(str.length());
    }
}

我不明白为什么春天如此不清楚异常。