我是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')
}
编辑:我读到某处弹簧使用反射来读取模块文件,因此我必须像这样添加open
关键字。
open module com.thanosfisherman.mancala {
requires spring.boot.autoconfigure;
requires spring.boot;
requires spring.web;
}
现在,我的应用可以正常运行,没有,而没有devtools依赖性,但是具有依赖性时,再次引发另一个错误。
java.lang.IllegalStateException:无法评估条件 org.springframework.boot.devtools.autoconfigure.DevToolsDataSourceAutoConfiguration 由于找不到javax / sql / DataSource。确保自己的 配置不依赖该类。如果您也可能发生这种情况 是@ComponentScanning springframework软件包(例如,如果您放置了一个 @ComponentScan误装到默认软件包中)
答案 0 :(得分:1)
这意味着默认情况下,类路径上的代码无法访问此模块。需要使用Java 9的return -1 if Object o.point_num < this.point_num
return 1 if Object o.point_num > this.point_num
return 0 if Object o.point_num = this.point_num
的{{1}}选项手动添加。
--add-modules
所以要逐步添加它们。
答案 1 :(得分:1)
我遇到了同样的问题,但是在jdk8上(不涉及任何模块),因为我的主类不是公开的。
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
/*public*/ class MyApp {
public static void main(String[] args) {
SpringApplication.run(LocationsTest.class, args);
}
}