question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to use Spring webmvc/webflux integrations in the same application

See original GitHub issue

Description

We are trying to set up updatable/createable entity views for our Spring application. When using these entity views in request bodies, Spring has no way of deserializing the json to the entity views so we need to use the spring webmvc/webflux integrations.

When attempting to use the spring webmvc integration alone, everything works as expected for version 1.6.0. However, version 1.6.3 has an issue with our webflux endpoints (this is not a problem on 1.6.0, but we need to be on 1.6.3 in order for validation annotations to work properly).

Example of the internal server error we get on all webflux related endpoints when on version 1.6.3 (Note, these webflux endpoints return entity views)

org.hibernate.exception.GenericJDBCException: could not advance using next()
	at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
	at org.hibernate.internal.ScrollableResultsImpl.convert(ScrollableResultsImpl.java:71)
	at org.hibernate.internal.ScrollableResultsImpl.next(ScrollableResultsImpl.java:106)
	at org.hibernate.query.internal.ScrollableResultsIterator.hasNext(ScrollableResultsIterator.java:33)
	at java.base/java.util.Spliterators$IteratorSpliterator.tryAdvance(Spliterators.java:1811)
	at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.lambda$initPartialTraversalState$0(StreamSpliterators.java:294)
	at java.base/java.util.stream.StreamSpliterators$AbstractWrappingSpliterator.fillBuffer(StreamSpliterators.java:206)
	at java.base/java.util.stream.StreamSpliterators$AbstractWrappingSpliterator.doAdvance(StreamSpliterators.java:161)
	at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.tryAdvance(StreamSpliterators.java:300)
	at java.base/java.util.Spliterators$1Adapter.hasNext(Spliterators.java:681)
	at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:132)
	at reactor.core.publisher.FluxStream.subscribe(FluxStream.java:71)
	at reactor.core.publisher.FluxUsing.subscribe(FluxUsing.java:102)
	at reactor.core.publisher.Flux.subscribe(Flux.java:8185)
	at reactor.core.publisher.FluxConcatArray$ConcatArraySubscriber.onComplete(FluxConcatArray.java:208)
	at reactor.core.publisher.FluxConcatArray.subscribe(FluxConcatArray.java:80)
	at reactor.core.publisher.Flux.subscribe(Flux.java:8185)
	at reactor.core.publisher.MonoFlatMapMany$FlatMapManyMain.onNext(MonoFlatMapMany.java:195)
	at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1815)
	at reactor.core.publisher.MonoCompletionStage.lambda$subscribe$0(MonoCompletionStage.java:82)
	at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:859)
	at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:837)
	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1705)
	at org.springframework.security.concurrent.DelegatingSecurityContextRunnable.run(DelegatingSecurityContextRunnable.java:82)
	at io.github.jhipster.async.ExceptionHandlingAsyncTaskExecutor.lambda$createWrappedRunnable$1(ExceptionHandlingAsyncTaskExecutor.java:78)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.postgresql.util.PSQLException: This ResultSet is closed.
	at org.postgresql.jdbc.PgResultSet.checkClosed(PgResultSet.java:2905)
	at org.postgresql.jdbc.PgResultSet.next(PgResultSet.java:1924)
	at com.zaxxer.hikari.pool.HikariProxyResultSet.next(HikariProxyResultSet.java)
	at org.hibernate.internal.ScrollableResultsImpl.next(ScrollableResultsImpl.java:101)
	... 26 common frames omitted

In an attempt to fix this issue, I also added the spring webflux integration for blaze. At this point, both dependencies are added to the project. This is the exception we see when attempting to start the application:

Description:

Parameter 0 of method entityViewIdAwareWebFilter in com.blazebit.persistence.spring.data.webflux.impl.BlazePersistenceWebConfiguration required a bean of type 'org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping' that could not be found.


Action:

Consider defining a bean of type 'org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping' in your configuration.

Finally, I wanted to see if we could get the spring webflux integration working alone. Here is the issue we get when attempting to get the webflux integration working by itself (no webmvc integration dependency)

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'keysetPageableResolver' defined in class path resource [com/blazebit/persistence/spring/data/webflux/impl/BlazePersistenceWebConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.blazebit.persistence.spring.data.webflux.impl.KeysetPageableHandlerMethodArgumentResolver]: Factory method 'keysetPageableResolver' threw exception; nested exception is java.lang.IllegalStateException: @Bean method BlazePersistenceWebConfiguration.sortResolver called as bean reference for type [com.blazebit.persistence.spring.data.webflux.impl.SortHandlerMethodArgumentResolver] but overridden by non-compatible bean instance of type [org.springframework.data.web.SortHandlerMethodArgumentResolver]. Overriding bean of same name declared in: class path resource [org/springframework/data/web/config/SpringDataWebConfiguration.class]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1334)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:769)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:326)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.blazebit.persistence.spring.data.webflux.impl.KeysetPageableHandlerMethodArgumentResolver]: Factory method 'keysetPageableResolver' threw exception; nested exception is java.lang.IllegalStateException: @Bean method BlazePersistenceWebConfiguration.sortResolver called as bean reference for type [com.blazebit.persistence.spring.data.webflux.impl.SortHandlerMethodArgumentResolver] but overridden by non-compatible bean instance of type [org.springframework.data.web.SortHandlerMethodArgumentResolver]. Overriding bean of same name declared in: class path resource [org/springframework/data/web/config/SpringDataWebConfiguration.class]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
	... 18 common frames omitted
Caused by: java.lang.IllegalStateException: @Bean method BlazePersistenceWebConfiguration.sortResolver called as bean reference for type [com.blazebit.persistence.spring.data.webflux.impl.SortHandlerMethodArgumentResolver] but overridden by non-compatible bean instance of type [org.springframework.data.web.SortHandlerMethodArgumentResolver]. Overriding bean of same name declared in: class path resource [org/springframework/data/web/config/SpringDataWebConfiguration.class]
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.resolveBeanReference(ConfigurationClassEnhancer.java:386)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:334)
	at com.blazebit.persistence.spring.data.webflux.impl.BlazePersistenceWebConfiguration$$EnhancerBySpringCGLIB$$65a6d753.sortResolver(<generated>)
	at com.blazebit.persistence.spring.data.webflux.impl.BlazePersistenceWebConfiguration.keysetPageableResolver(BlazePersistenceWebConfiguration.java:68)
	at com.blazebit.persistence.spring.data.webflux.impl.BlazePersistenceWebConfiguration$$EnhancerBySpringCGLIB$$65a6d753.CGLIB$keysetPageableResolver$2(<generated>)
	at com.blazebit.persistence.spring.data.webflux.impl.BlazePersistenceWebConfiguration$$EnhancerBySpringCGLIB$$65a6d753$$FastClassBySpringCGLIB$$68ec23ea.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
	at com.blazebit.persistence.spring.data.webflux.impl.BlazePersistenceWebConfiguration$$EnhancerBySpringCGLIB$$65a6d753.keysetPageableResolver(<generated>)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
	... 19 common frames omitted

Expected behavior

We should be able to use both spring-webmvc and spring-webflux integrations for the same project since we do use both webmvc and webflux throughout. EntityViews should be properly deserialized when passed as request bodies on both webflux and webmvc endpoints.

Actual behavior

Multiple outcomes noted above during troubleshooting. Unable to get spring integrations working properly with our solution.

Steps to reproduce

A Spring project using blaze 1.6.3 that also utilizes webmvc and webflux together. I can assist in clarifying this step with additional details if needed. I believe the description covers this mostly.

Environment

Version: 1.6.3
JPA-Provider: Hibernate 5.4.29.Final (Spring Data JPA 2.4.4)
DBMS: PostgreSQL 9.6
Application Server: Spring Boot 2.4.4

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jwgmeligmeylingcommented, Nov 22, 2021

Result set streaming was only added recently (#1344) and it could be that there is an issue still with entity views. It appears as if the underlying scrollable result is closed before the (transformed?) stream is consumed. Could you perhaps put a breakpoint on ScrollableResults#close and back track what calls it? Wondering whether this could be a Hibernate or Blaze-Persistence bug.

As a workaround you can temporarily use getResultList().stream(). I don’t think this original issue was even related to WebMvc and Webflux interopability.

1reaction
jason-visotrustcommented, Nov 23, 2021

As a workaround you can temporarily use getResultList().stream(). I don’t think this original issue was even related to WebMvc and Webflux interopability.

I specifically built this using streaming because the result sets are large. Any idea what’s breaking this in 1.6.3?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Having spring-webmvc in as a dependency breaks webflux ...
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ...
Read more >
Can I use SpringMvc and webflux together? - Stack Overflow
1 Answer 1 · Spring MVC can't run on Netty · both infrastructure will compete for the same job (for example, serving static...
Read more >
Web on Reactive Stack - Spring
Applications can use one or the other module or, in some cases, both — for example, Spring MVC controllers with the reactive WebClient...
Read more >
Spring WebFlux - Spring Reactive Programming - DigitalOcean
Let's built a simple Spring WebFlux Hello World application. We will create a simple rest web service and use Spring Boot to run...
Read more >
Sending HTTP requests with Spring WebClient - Reflectoring
This is designed to co-exist alongside the existing Spring Web MVC APIs, but to add support for non-blocking designs. Using WebFlux, you can ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found