-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Avoid using @ConditionalOnClass(Flux.class) and similar conditions #15574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Unless I'm missing something, the first instance in Worst case scenario, the application only declares blocking Now about the second case; it's true that this |
For Servlet based app, I don't think the choice of Redis driver should influence whether reactive infrastructure should be configured. This is what happens now - if I use Jedis there's no That's why I think that relying on the presence of Project Reactor on classpath isn't the right thing to do here, but rather to react to the fact that some of the Spring Data's components for reactive Redis have been configured. I don't do much reactive so I don't know what would be the best thing to do here, but since core of Project Reactor is simply a foundation for building reactive apps and can be used in so many different scenarios, I don't think its mere presence on classpath should influence how infrastructure is set up. |
Indeed, using Jedis doesn't trigger this piece of infrastructure; but I'm not seeing any downside in enabling that actuator part in case reactive bits are present. Even if the health indicators are not exposed through a web interface, they'll still be executed in a more efficient way. Setting up a condition on Spring Data doesn't really matter here, since the health indicator usually rely on low-level constructs/drivers. As you said, Reactor is a foundation for reactive libraries and it's the best signal we can pick up here IMO. The team has discussed that point and we feel that attempting to change that might result in blocking reactive infrastructure in some cases, whereas right now worst thing that can happen is wrapping blocking infrastructure with non-blocking calls. |
The current Spring Boot codebase contains two instances of
@ConditionalOnClass(Flux.class)
:spring-boot/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorAutoConfiguration.java
Lines 83 to 85 in 7946bec
spring-boot/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/reactive/ReactiveManagementContextAutoConfiguration.java
Lines 35 to 38 in 7946bec
When a Servlet based app depends on a library that transitively pulls in Project Reactor as mandatory dependency, such as Lettuce, the first example will result in
ReactiveHealthIndicatorRegistry
bean registered, which I believe shouldn't be the case in a Servlet app.The second example is benign and has no consequences, but arguably having
@ConditionalOnClass(Flux.class)
there is needless as it will get shadowed by@ConditionalOnWebApplication(type = Type.REACTIVE)
.IMO the conditions that test the presence of Project Reactor on classpath should be avoided due to high likeliness of false positives, unless there's really a valid case for those.
The text was updated successfully, but these errors were encountered: