我是 Java 模块的新手。我一直在尝试让 DevTools 与拼图模块一起使用,但出现以下错误
线程“restartedMain”java.lang.IllegalAccessException 中的异常:类 org.springframework.boot.devtools.restart.RestartLauncher(在模块 spring.boot.devtools 中)无法访问类 com.thanosfisherman.mancala.MancalaApplication(在模块 com.thanosfisherman. mancala) 因为模块 com.thanosfisherman.mancala 不会将 com.thanosfisherman.mancala 导出到模块 spring.boot.devtools
我应该在我的module-info.java文件中放入什么以便应用程序可以正常运行?
module-info.java
module com.thanosfisherman.mancala {
requires spring.web;
requires spring.boot.autoconfigure;
requires spring.boot;
}
请注意,我使用的是 Gradle。这是我的 gradle 配置脚本
buildscript {
ext {
springBootVersion = '2.1.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.thanosfisherman'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 11
repositories {
mavenCentral()
}
dependencies {
implementation('org.springframework.boot:spring-boot-starter-actuator')
implementation('org.springframework.boot:spring-boot-starter-web')
runtimeOnly('org.springframework.boot:spring-boot-devtools')
runtimeOnly('org.postgresql:postgresql')
testImplementation('org.springframework.boot:spring-boot-starter-test')
}
编辑:我在某处读到 spring 使用反射来读取模块文件,所以我必须open像这样添加关键字。
open module com.thanosfisherman.mancala {
requires spring.boot.autoconfigure;
requires spring.boot;
requires spring.web;
}
现在我的应用程序在没有devtools 依赖项的情况下正常运行,但再次引发了与依赖项不同的错误。
java.lang.IllegalStateException:由于找不到 javax/sql/DataSource,无法评估 org.springframework.boot.devtools.autoconfigure.DevToolsDataSourceAutoConfiguration 的条件。确保您自己的配置不依赖于该类。如果您正在 @ComponentScanning 一个 springframework 包,也会发生这种情况(例如,如果您错误地将 @ComponentScan 放入默认包中)