dgs-framework icon indicating copy to clipboard operation
dgs-framework copied to clipboard

Websocket subscription with Webflux

Open rhdeandrade opened this issue 2 years ago • 2 comments

Hi, I've been trying to implement Subscriptions in our project with Websocket and Webflux, however I'm getting an error and as per documentation and other questions I've read it should work.

I'm using the following dependencies on my project:

 <dependency>
			<groupId>com.netflix.graphql.dgs</groupId>
			<artifactId>graphql-dgs-webflux-starter</artifactId>
		</dependency>

		<dependency>
			<groupId>com.netflix.graphql.dgs</groupId>
			<artifactId>graphql-dgs-subscriptions-websockets-autoconfigure</artifactId>
		</dependency>

		<dependency>
			<groupId>com.netflix.graphql.dgs</groupId>
			<artifactId>graphql-dgs-spring-webflux-autoconfigure</artifactId>
		</dependency>

But I'm still getting this error:

Caused by: java.lang.ClassNotFoundException: org.springframework.web.servlet.HandlerMapping at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[na:na] at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[na:na]

I'm on version:

5.5.0

rhdeandrade avatar Aug 04 '23 13:08 rhdeandrade

Hi @rhdeandrade! The error message you've shared indicates that the class org.springframework.web.servlet.HandlerMapping is not found in the classpath. This typically suggests that there might be a compatibility issue between the Spring modules you're using and the version of Spring Boot you're on. It looks like the graphql-dgs-webflux-starter dependency is trying to load a class from the Spring Web MVC module (spring-webmvc), which might not be compatible with the WebFlux setup you're using.

Could you please try making sure the Spring Boot version you're using is compatible with the Spring WebFlux setup and the DGS dependencies you have? You mentioned you are on DGS version 5.5.0, so you should be on Spring Boot 2.7.

If you don't find any version conflicts there, perhaps you could try excluding some of the transitive dependencies of graphql-dgs-webflux-starter that might be pulling in Spring Web MVC.

congotej avatar Aug 09 '23 18:08 congotej

Remove the following deps:

<dependency>
  <groupId>com.netflix.graphql.dgs</groupId>
  <artifactId>graphql-dgs-subscriptions-websockets-autoconfigure</artifactId>
</dependency>

<dependency>
  <groupId>com.netflix.graphql.dgs</groupId>
  <artifactId>graphql-dgs-spring-webflux-autoconfigure</artifactId>
</dependency>

The graphql-dgs-subscriptions-websockets-autoconfigure is for webmvc stack, and webflux starter includes graphql-dgs-spring-webflux-autoconfigure as transitive dep.

hantsy avatar Jan 24 '24 03:01 hantsy

Closing this as it is an old issue with a solution. Also, this has changed with the integration of DGS / Spring Graphql.

paulbakker avatar Aug 16 '24 21:08 paulbakker