首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >运行spring + spring java 9项目,使用java.lang.NoClassDefFoundError结束: java/sql/SQLException

运行spring + spring java 9项目,使用java.lang.NoClassDefFoundError结束: java/sql/SQLException
EN

Stack Overflow用户
提问于 2018-03-03 18:34:41
回答 1查看 550关注 0票数 3

我有一个非常简单的应用程序,它与Java1.8完美地工作,它包含一个主类,如

代码语言:javascript
复制
package com.company.getworks.start;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan()
@EnableAutoConfiguration
public class ApplicationMain {

    public static void main(String[] args) {
        SpringApplication.run(ApplicationMain.class, args);
    }

}

和一个带有@RestContoller的类,它只包含一个带有@RequestMapping("/hello")的方法

我添加了模块-info.java,看起来像

代码语言:javascript
复制
module com.company.getworks.start {
    requires spring.boot;
    requires spring.webmvc;
}

我的build.gradle是

代码语言:javascript
复制
group 'com.company'
version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = 1.9

repositories {
    mavenCentral()
}

dependencies {
    final def springVersion='4.3.10.RELEASE'
    final def springBootVersion='1.5.6.RELEASE'
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile (group: 'org.springframework', name: 'spring-webmvc', version: springVersion) {
        exclude group: 'commons-logging', module: 'commons-logging'
    }
    compile(group: "org.springframework.boot", name: "spring-boot-starter-web", version: springBootVersion) {
        exclude group: 'commons-logging', module: 'commons-logging'
    }
}

ext.moduleName = 'com.company.getworks.start'

compileJava {
    inputs.property("moduleName", moduleName)
    doFirst {
        options.compilerArgs = [
            '--module-path', classpath.asPath,
            '--add-modules', 'spring.boot',
            '--add-modules', 'spring.webmvc',
    ]
    classpath = files()
    }
}

运行clean compileJava以成功构建结束,但是当我试图运行ApplicationMain.java时,它以Exception in thread "main" java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.context.ApplicationContextInitializer : org.springframework.boot.context.ConfigurationWarningsApplicationContextInitializer Caused by: java.lang.NoClassDefFoundError: java/sql/SQLException结尾,我做错了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-04 15:52:18

我不得不

1)升级到弹簧引导2

2)将我的依赖项列表更改为

代码语言:javascript
复制
dependencies {
    final def springVersion='4.3.10.RELEASE'
    final def springBootVersion='2.0.0.RELEASE'
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile (group: 'org.springframework', name: 'spring-webmvc', version: springVersion) {
        exclude group: 'commons-logging', module: 'commons-logging'
    }
    compile(group: "org.springframework.boot", name: "spring-boot-starter-web", version: springBootVersion) {
        exclude group: 'commons-logging', module: 'commons-logging'
        exclude group: 'javax.annotation', module: 'javax.annotation-api'
    }
}

3)更新模块-info.java

代码语言:javascript
复制
module com.company.getworks.start {
    requires spring.boot;
    requires spring.webmvc;
    requires spring.context;
    requires spring.boot.autoconfigure;
    requires spring.web;
    opens com.company.getworks.start;
    exports com.company.getworks.web;
}

其中com.company.getworks.web是包含我的@RestController类的包

4)正如正确地提到的,@miroh add java.sql是我的java命令。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49087753

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档