Hello team, This is a call for help .. I'm working...
# help
i
Hello team, This is a call for help .. I'm working on integration testing of a microservice and I'm using wiremock-spring-boot to stub external APIs during tests. I refer to this docs page and those examples. I'm getting few errors that seem related to dependencies conflicts .. When I first ran my tests with
wiremock-spring-boot 3.6
, I got this:
Copy code
java.lang.NoClassDefFoundError: org/eclipse/jetty/servlet/ServletContextHandler

	at com.github.tomakehurst.wiremock.jetty.JettyHttpServerFactory.buildHttpServer(JettyHttpServerFactory.java:28)
	at com.github.tomakehurst.wiremock.WireMockServer.<init>(WireMockServer.java:75)
	at org.wiremock.spring.internal.WireMockServerCreator.createWireMockServer(WireMockServerCreator.java:93)
	at org.wiremock.spring.internal.WireMockContextCustomizer.resolveOrCreateWireMockServer(WireMockContextCustomizer.java:57)
	at org.wiremock.spring.internal.WireMockContextCustomizer.customizeContext(WireMockContextCustomizer.java:47)
	at org.springframework.boot.test.context.SpringBootContextLoader$ContextCustomizerAdapter.initialize(SpringBootContextLoader.java:435)
	at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:607)
	at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:387)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:311)
	at org.springframework.boot.test.context.SpringBootContextLoader.lambda$loadContext$3(SpringBootContextLoader.java:137)
	at org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:58)
	at org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:46)
	at org.springframework.boot.SpringApplication.withHook(SpringApplication.java:1406)
	at org.springframework.boot.test.context.SpringBootContextLoader$ContextLoaderHook.run(SpringBootContextLoader.java:545)
	at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:137)
	at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:108)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119)
	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:141)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:97)
	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:241)
	...
I tried to add wiremock-jetty12 dependency, but ran into this
Copy code
java.lang.NoClassDefFoundError: org/eclipse/jetty/server/ConnectionMetaData at java.base/java.lang.ClassLoader.defineClass1(Native Method) at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1023) 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:525) at com.github.tomakehurst.wiremock.jetty11.Jetty11HttpServer.createHttpConnector(Jetty11HttpServer.java:90) at com.github.tomakehurst.wiremock.jetty.JettyHttpServer.<init>(JettyHttpServer.java:79) at com.github.tomakehurst.wiremock.jetty11.Jetty11HttpServer.<init>(Jetty11HttpServer.java:76) at com.github.tomakehurst.wiremock.jetty.JettyHttpServerFactory.buildHttpServer(JettyHttpServerFactory.java:28) at com.github.tomakehurst.wiremock.WireMockServer.<init>(WireMockServer.java:75) at org.wiremock.spring.internal.WireMockServerCreator.createWireMockServer(WireMockServerCreator.java:93) at org.wiremock.spring.internal.WireMockContextCustomizer.resolveOrCreateWireMockServer(WireMockContextCustomizer.java:57)
Last, I tried to force jetty12 and exclude jetty11 but got this
Copy code
error java.lang.NoClassDefFoundError: org/eclipse/jetty/http/MimeTypes$Mutable at org.eclipse.jetty.server.Server.<init>(Server.java:85) at org.eclipse.jetty.server.Server.<init>(Server.java:141) at com.github.tomakehurst.wiremock.jetty.JettyHttpServer.createServer(JettyHttpServer.java:125) at com.github.tomakehurst.wiremock.jetty.JettyHttpServer.<init>(JettyHttpServer.java:70) at com.github.tomakehurst.wiremock.jetty12.Jetty12HttpServer.<init>(Jetty12HttpServer.java:74) at com.github.tomakehurst.wiremock.jetty12.Jetty12HttpServerFactory.buildHttpServer(Jetty12HttpServerFactory.java:33) at com.github.tomakehurst.wiremock.WireMockServer.<init>(WireMockServer.java:75)
Could you please assist in how to fix this dependencies issue so I can use wiremock smoothly🙏 for reference, Spring Boot version is (v3.1.2) Thanks
l
From what I can tell Spring Boot
3.1.2
still uses jetty 11. Are you fixed to that version of Spring Boot or can you upgrade ?
i
For now, I'm fixed to this version of Spring Boot
l
Is there any chance you can put together a small project that reproduces the issue so we can help diagnose the issue?
i
Sure! will try to do shortly and share it with you.
But for now, is there any trusted working way with this version of Spring boot?
l
Thank you very much, that would be very helpful
🙏 1
We have a few examples here - https://github.com/wiremock/wiremock-examples
👍 1
Not sure how helpful they will be given your version of spring boot
We normally point people to the official integration - https://github.com/wiremock/wiremock-spring-boot That repo do have some running examples - https://github.com/wiremock/wiremock-spring-boot/tree/main/src/test/java/usecases
i
Thank you for sharing these references, will check them