WebFlux is the reactive web framework for Spring.
The programming model is easy but using it could be cumbersome if you don’t know the consequences when used incorrectly.
This post will show what the consequences are when the reactive-stack is not used correctly.
It will answer the question: why is my (health) endpoint sometimes so slow?
TL DR; Don’t block the event loop
Continue reading →
Spring offers several frameworks to implement server side rendered web pages and REST APIS.
In this blog I compare three options:
-
traditional, servlet based (spring-web),
-
reactive, Netty based (spring-webflux) and
-
DSL, reactive, Netty based (spring-jafu)
Continue reading →
In a previous post we learned that configuration property values can be passed via environment variables. With Spring Boot we can also pass the values using Java system properties. So if we have a property sample.message
then we can use -Dsample.message=value
to pass a value when we run the application. If we use the Spring Boot Gradle plugin we must reconfigure the bootRun
task to pass Java system properties from the command-line.
Continue reading →
Spring Boot has many options for externalising the configuration of our application. One of the options it to use OS environment variables. We need to follow certain rules to name the environment variable and then Spring Boot will use the value of variable to set a configuration property. The property name must be in uppercase and any dots need to be replaced with underscores. For example the configuration property sample.message
is set with the environment variable SAMPLE_MESSAGE
. This feature can be useful in a continuous integration environment where we can set environment variables or just when developing locally. The nice thing is that this also works when we use the Spring Boot Gradle plugin. The environment variables are passed on to the Java process that the bootRun
task starts.
Continue reading →
The auto-configuration feature in Spring Boot adds beans to our application context based on conditions. For example based on the availability of a class on the class path or a environment property beans are enabled or disabled. We must apply the @EnableAutoConfiguration
or @SpringBootApplicaiton
in our Spring Boot application to make this work. To get an overview of all the configurations that had positive and negative conditional matches in our application we can use the --debug
command-line option. This will print out a report to System.out with a complete overview. We can check why a configuration is applied or not.
Continue reading →
When we develop a Spring Boot application we can hot reload newly compiled classes using Gradle. The bootRun
task of the Spring Boot Gradle plugin has support for Spring Loaded. We must add a dependency to Spring Loaded as a dependency for the classpath
configuration in the buildscript
block. If we now use the bootRun
task everything is ready to reload changed classes. Now we can use the continuous build feature of Gradle to listen for changes in our source files to recompile them. The recompiled classes are then reloaded in the running Spring Boot application started with bootRun
. We start a second Gradle instance with the -t
option for the classes
task. This way when we change a source file it gets recompiled automatically and reloaded.
Continue reading →
In Spring we can use the @Value
annotation to set property or arguments values based on a SpEL expression. If we want to use the @Value
annotation for a constructor argument we must not forget to add the @Autowired
annotation on the constructor as well.
Continue reading →