我有一个非常简单的应用程序,它与Java1.8完美地工作,它包含一个主类,如
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,看起来像
module com.company.getworks.start {
requires spring.boot;
requires spring.webmvc;
}我的build.gradle是
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结尾,我做错了什么?
发布于 2018-03-04 15:52:18
我不得不
1)升级到弹簧引导2
2)将我的依赖项列表更改为
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
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命令。
https://stackoverflow.com/questions/49087753
复制相似问题