Spring Boot在模块化Java中配置DevTools
我不熟悉Java模块。我一直试图让DevTools与jigsaw模块一起工作,但我得到了以下错误 线程“restartedMain”java.lang.IllegalAccessException中的异常: 类org.springframework.boot.devtools.restart.RestartLauncher(在 模块spring.boot.devtools)无法访问类 com.thanosfisherman.mancala.mancala应用程序(模块中 因为模块 com.thanosfisherman.mancala不导出 com.thanosfisherman.mancala到模块spring.boot.devtools 我应该在我的Spring Boot在模块化Java中配置DevTools,java,spring,spring-boot,java-platform-module-system,Java,Spring,Spring Boot,Java Platform Module System,我不熟悉Java模块。我一直试图让DevTools与jigsaw模块一起工作,但我得到了以下错误 线程“restartedMain”java.lang.IllegalAccessException中的异常: 类org.springframework.boot.devtools.restart.RestartLauncher(在 模块spring.boot.devtools)无法访问类 com.thanosfisherman.mancala.mancala应用程序(模块中 因为模块 com.tha
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:无法计算上的条件
org.springframework.boot.devtools.autoconfigure.DevToolsDataSourceAutoConfiguration
由于javax/sql/DataSource未找到。确保你自己的
配置不依赖于该类。如果您
@Component是否正在扫描springframework包(例如,如果您将
@组件(错误地扫描默认包中的组件)
这意味着默认情况下类路径上的代码无法访问此模块。它需要使用Java9的
javac
的--addmodules
选项手动添加
compileJava {
options.compilerArgs += ["--add-modules", "spring.boot.devtools"]
}
所以,一步一步地添加它们。我也有同样的问题,但是在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);
}
}
我将其添加到gradle脚本中,但仍然出现相同的错误。您是否已将
spring.boot.devtools
添加到模块文件中?是的,我尝试添加requires spring.boot.devtools
但Intellij将其标记为错误,表示模块不在dependencies:spring.boot.devtools
中,如果查看gradle脚本,devtools的dependency默认设置为runtimeOnly
https://start.spring.io/那么要么我必须将其从java模块系统中完全排除?我不知道。试着在没有devtools的情况下运行它