gpt4 book ai didi

java - 未能获得 JDK 11、Spring Boot(包括)的组合。持久性和 JavaFX 工作

转载 作者:行者123 更新时间:2023-12-02 01:15:49 25 4
gpt4 key购买 nike

我使用的是 JDK 11。我的项目是作为具有持久性的 Spring Boot 项目开始的,我首先将所有数据类连接起来并进行测试。现在我想将 JavaFX 用于 GUI 目的,这意味着开始使用 Java 模块系统。应用程序(如下所示的代码框架)启动到一半,但随后由于以下异常堆栈而中断:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.jpa-org.springframework.boot.autoconfigure.orm.jpa.JpaProperties': Lookup method resolution failed

Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.boot.autoconfigure.orm.jpa.JpaProperties] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@6c3708b3]

Caused by: java.lang.NoClassDefFoundError: javax/sql/DataSource

Caused by: java.lang.ClassNotFoundException: javax.sql.DataSource

模块信息当前如下所示:

requires java.persistence;
requires javafx.controls;
requires spring.boot;
requires spring.boot.autoconfigure;
requires spring.context;
requires spring.core;

exports mypackage.app;
opens mypackage.app;

这是主应用程序的(稍微缩小的)Java 源代码:

package mypackage.app;

@SpringBootApplication
public class MyApplication extends Application {

private static String[] arguments;

private ConfigurableApplicationContext applicationContext;

public static void main(String[] args) {
arguments = args;
launch(args);
}

@Override
public void init() throws Exception {
applicationContext = SpringApplication.run(MyApplication.class, arguments);
}

@Override
public void start(Stage stage) throws Exception {
var label = new Label("xyz");
var scene = new Scene(new StackPane(label), 640, 480);
stage.setScene(scene);
stage.show();
}

@Override
public void stop() {
applicationContext.stop();
}

}

编辑。

requires java.sql; 添加到模块信息会导致不同的异常堆栈,在此处复制:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed

javax.persistence.PersistenceException: Unable to resolve persistence unit root URL

java.io.FileNotFoundException: class path resource [] cannot be resolved to URL because it does not exist

编辑。

如图所示elsewhere ,添加 java.xml.bind 依赖项解决了持久性单元根 URL 问题,只是将其替换为新的异常堆栈:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed

java.lang.NoClassDefFoundError: net/bytebuddy/matcher/ElementMatchers

java.lang.ClassNotFoundException: net.bytebuddy.matcher.ElementMatchers

最佳答案

以下module-info.java解决了该问题:

requires java.persistence;
requires java.sql;
requires java.xml.bind;
requires javafx.controls;
requires net.bytebuddy;
requires spring.boot;
requires spring.boot.autoconfigure;
requires spring.context;
requires spring.core;
requires spring.data.jpa;

exports mypackage.app;
opens mypackage.app;

简而言之,必须添加的依赖项是 java.sqlspring.data.jpajava.xml.bindnet.bytebuddy。而且,应用程序包需要通过最后两行来打开和导出。

关于java - 未能获得 JDK 11、Spring Boot(包括)的组合。持久性和 JavaFX 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57239917/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com