I am trying Solr v9.3 to test their capabilities. I have created a test application with Spring Boot v3.1.1, and included a small test where I am using a EmbeddedSolrServer
.
No so much code, and is based on some examples I have found:
EmbeddedSolrServer solrClient = new EmbeddedSolrServer(solrHome, coreName);
// create a test document
SolrInputDocument document1 = new SolrInputDocument();
document1.addField("id", "1");
SolrInputDocument document2 = new SolrInputDocument();
document2.addField("id", "2");
solrClient.add(Arrays.asList(document1, document2));
The problem is that when executing, I get a:
java.lang.NoClassDefFoundError: javax/ws/rs/core/Application
at org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.<init>(EmbeddedSolrServer.java:98)
...
Usually, the solution for this bug, is to add some dependencies, such as:
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>2.1.6</version>
</dependency>
But now, I get a:
java.lang.NoClassDefFoundError: jakarta/ws/rs/core/Configurable
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1013)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.<init>(EmbeddedSolrServer.java:98)
...
Probably that means that Solr is not prepared for using jakarta
packages, and therefore is not compatible with Sprint Boot 3.X. Does somebody has success in using Solr EmbeddedSolrServer in Spring Booty 3.X? Or it is know that is not compatible (yet)?
You are correct that Spring Boot 3 will not be compatible with Solr 9.3 due to the different Jetty versions.
We expect to ship Solr 10.0 based on Jetty 12 in late 2024 which should better align on the jakarta
namespace.
Note that using EmbeddedSolrServer is not recommended and is an expert option for rare use cases. It will cause the entire solr-core
application with all its dependencies to be running within your application's JVM and risk causing many more library conflicts.
A better option is to start Solr as a standalone server (e.g. through bin/solr start
or through Docker docker run -p 8983:8983 solr:9
), and then use SolrJ client to connect to the Solr server. You can then use SpringBoot 3 and the HttpSolrClient
by excluding all jetty
dependencies from your maven SolrJ import, to avoid javax/jakarta clash. Excluding jetty classes is safe since HttpSolrClient
depends on a different http client.