应用程序启动失败java.lang.NoClassDefFoundError:org / springframework / util / StopWatch $ TaskInfo

时间:2016-12-06 12:24:50

标签: java spring spring-boot

我使用Spring Boot 1.4.2开发了一个批处理程序,需要很长时间(约5小时)才能执行。程序启动后经过大约5个小时后,它将完成执行,并显示以下错误消息:

20:49:01.324 ERROR o.s.boot.SpringApplication - Application startup failed
java.lang.NoClassDefFoundError: org/springframework/util/StopWatch$TaskInfo
    at org.springframework.util.StopWatch.stop(StopWatch.java:146)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:318)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)
    at com.example.Main.main(Main.java:25)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:58)
Caused by: java.lang.ClassNotFoundException: org.springframework.util.StopWatch$TaskInfo
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 13 common frames omitted
Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:58)
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/SpringBootExceptionHandler
    at org.springframework.boot.SpringApplication.getSpringBootExceptionHandler(SpringApplication.java:903)
    at org.springframework.boot.SpringApplication.registerLoggedException(SpringApplication.java:850)
    at org.springframework.boot.SpringApplication.reportFailure(SpringApplication.java:840)
    at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:816)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:326)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)
    at jp.co.cyberagent.leeds.article_batches.ArticleBatchesApplication.main(ArticleBatchesApplication.java:25)
    ... 8 more
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringBootExceptionHandler
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 16 more

似乎我在Spring Framework上缺少一些依赖项,但我不知道我真正需要什么。

这是我的build.gradle

buildscript {
    ext {
        springBootVersion = '1.4.2.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'

jar {
    baseName = 'article-batches'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
    maven {
        url "https://maven.ca-tools.org/content/groups/public/"
    }
}


dependencies {
    compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.1.1')
    compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.7'
    compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.40'
    compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.2'
    compile group: 'org.mybatis', name: 'mybatis-typehandlers-jsr310', version: '1.0.1'
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

2 个答案:

答案 0 :(得分:0)

请将Spring Boot 1.4.2更改为1.4.1

似乎新版本存在一些问题。

答案 1 :(得分:0)

我自己解决了这个问题。我的主要流程是用run方法编写的,但在@SpringBootApplication public class Main { public static void main(String[] args) { final ConfigurableApplicationContext context = SpringApplication.run(Main.class, args); final AppBean app = context.getBean(AppBean.class); app.run(args); } } 方法中编写主流程是错误的,this comment在另一个问题中说。

我按照评论写了下面的主要流程,然后问题就消失了。

//CORS middleware
var allowCrossDomain = function(req, res, next) {
    res.header('Access-Control-Allow-Origin', 'example.com');
    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
    res.header('Access-Control-Allow-Headers', 'Content-Type');

    next();
}

//...
app.configure(function() {
    ...
    app.use(allowCrossDomain);
    ...
});