hapifhir / hapi-fhir-jpaserver-starter

Apache License 2.0
356 stars 977 forks source link

Unable to use spring-boot with jetty profile for HAPI 7.3.7-SNAPSHOT #700

Open dotasek opened 1 week ago

dotasek commented 1 week ago

When trying to execute the smoke tests in the HAPI release tracking branch (https://github.com/hapifhir/hapi-fhir-jpaserver-starter/pull/684), the running spring-boot using the jetty profile results in an exception and is unable to start the server.

Replication Steps

Run jpaserver-starter using the following command:

mvn -P jetty spring-boot:run

The following exception is thrown, and the server is not available:

2024-06-18 13:06:50.034 [main] ERROR o.s.boot.SpringApplication [SpringApplication.java:859] Application run failed
org.springframework.context.ApplicationContextException: Unable to start web server
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:165)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:618)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:335)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1352)
    at ca.uhn.fhir.jpa.starter.Application.main(Application.java:46)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jettyServletWebServerFactory' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryConfiguration$EmbeddedJetty.class]: org/eclipse/jetty/util/ClassMatcher
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:607)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:337)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:205)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:223)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:186)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:162)
    ... 8 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/eclipse/jetty/util/ClassMatcher
    at org.eclipse.jetty.ee10.webapp.AbstractConfiguration$Builder.<init>(AbstractConfiguration.java:37)
    at org.springframework.boot.autoconfigure.websocket.servlet.JettyWebSocketServletWebServerCustomizer.customize(JettyWebSocketServletWebServerCustomizer.java:44)
    at org.springframework.boot.autoconfigure.websocket.servlet.JettyWebSocketServletWebServerCustomizer.customize(JettyWebSocketServletWebServerCustomizer.java:39)
    at org.springframework.boot.web.server.WebServerFactoryCustomizerBeanPostProcessor.lambda$postProcessBeforeInitialization$0(WebServerFactoryCustomizerBeanPostProcessor.java:72)
    at org.springframework.boot.util.LambdaSafe$Callbacks.lambda$invoke$0(LambdaSafe.java:287)
    at org.springframework.boot.util.LambdaSafe$LambdaSafeCallback.invoke(LambdaSafe.java:159)
    at org.springframework.boot.util.LambdaSafe$Callbacks.lambda$invoke$1(LambdaSafe.java:286)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
    at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1092)
    at org.springframework.boot.util.LambdaSafe$Callbacks.invoke(LambdaSafe.java:286)
    at org.springframework.boot.web.server.WebServerFactoryCustomizerBeanPostProcessor.postProcessBeforeInitialization(WebServerFactoryCustomizerBeanPostProcessor.java:72)
    at org.springframework.boot.web.server.WebServerFactoryCustomizerBeanPostProcessor.postProcessBeforeInitialization(WebServerFactoryCustomizerBeanPostProcessor.java:58)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:422)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1780)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:600)
    ... 16 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.eclipse.jetty.util.ClassMatcher
    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:525)
    ... 31 common frames omitted
dotasek commented 1 week ago

There is already a potential solution here: https://github.com/hapifhir/hapi-fhir/pull/6022

From what I can tell, spring-boot-starter-jetty is picky about the version of jetty, and the versions should align. To see the appropriate jetty version, you can quickly check the dependency listing here (it is jetty 12.0.9) https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jetty/3.2.6

For comparison, the old version is here: https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jetty/3.2.0

I'm documenting this issue here in case anyone else runs into an issue when HAPI bumps the version of spring-boot.