I'm using JDK 11. My project started as a Spring Boot project with persistence, and I first got all the data classes wired up and covered in tests. Now I want to use JavaFX for GUI purposes, which meant starting to use the Java module system. The application (code skeleton shown below) starts up halfway but then breaks because of the following stack of exceptions:
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
The module info currently looks like this:
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;
And here is the (slightly shrinkwrapped) Java source of the main application:
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();
}
}
Edit.
Adding a requires java.sql;
to the module info leads to a different stack of exceptions, reproduced here:
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
Edit.
As indicated elsewhere, adding the java.xml.bind
dependency addressed the persistence unit root URL issue, only to replace it with a new stack of exceptions:
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