storage-restservice-sparkjava does not work in Quarkus
Environment Details
- EclipseStore Version: 1.2.0
- JDK version: openjdk version "21.0.2" 2024-01-16
- OS: Mac OS
- Used frameworks: Quarkus 3.8.1
Describe the bug
I use EclipseStore in Quarkus (in JVM-Mode) sucessfully after changing the ClassLoaderProvider according to https://stackoverflow.com/questions/65898882/quarkus-with-microstream-classloader-problems:
return EmbeddedStorageConfigurationBuilder.New()
..
.createEmbeddedStorageFoundation()
// TODO workaround see https://stackoverflow.com/questions/65898882/quarkus-with-microstream-classloader-problems
// default is "ClassLoader.getSystemClassLoader()"
.onConnectionFoundation(cf -> cf.setClassLoaderProvider(ClassLoaderProvider.New(Thread.currentThread().getContextClassLoader())))
..
.start();
However, when using the eclipse-store "rest-interface":
<dependency>
<groupId>org.eclipse.store</groupId>
<artifactId>storage-restservice-sparkjava</artifactId>
<version>1.2.0</version>
</dependency>
then quarkus does not start the application successfully and the following stacktrace is shown:
2024-03-01 10:38:59,512 INFO [org.ecl.ser.per.typ.PersistenceTypeHandlerManager] (Quarkus Main Thread) Initializing type handler manager Exception in thread "Thread-38" java.lang.NoClassDefFoundError: javax/servlet/Filter at spark.embeddedserver.EmbeddedServers.initialize(EmbeddedServers.java:41) at spark.Service.lambda$init$2(Service.java:618) at java.base/java.lang.Thread.run(Thread.java:1583) Caused by: java.lang.ClassNotFoundException: javax.servlet.Filter at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526) at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:518) at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:468) ... 3 more
I also tried to use another spark-version as suggested in https://github.com/microstream-one/microstream/issues/238:
<dependency>
<groupId>org.eclipse.store</groupId>
<artifactId>storage-restservice-sparkjava</artifactId>
<version>1.2.0</version>
</dependency>
<!-- workaround because of: https://github.com/microstream-one/microstream/issues/238 -->
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.8.0</version>
</dependency>
I also tried to solve this issue by making the javax.servlet-api-dependency explicit:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
But that doesn't help. Looking at the classpath I can see that javax.servlet.api exists:
To Reproduce
Use EclipseStore in Quarkus and initialize a StorageRestService by storage-restservice.
Expected behavior
Using a StorageRestService should work.
Hello,
The spark-java REST service was intended to provide the Api to standalone java apps too, that’s why it has jetty and other stuff included. There is currently no other implementation. As Quarkus provides a great REST support you may implement the four required routes directly in your app to get rid of the sparkjava implementation. Please see the Microstream issues #549 and #695 for additional information.
Ok, thanks for the information. I will try to create a RestClient in Quarkus consuming the endpoints like in https://github.com/microstream-one/microstream/issues/695#issuecomment-1964938327.
By the way, a possible Quarkus extension in the future could potentially provide these REST endpoints by default for the Quarkus DevConsole and the application itself.