JaFu (for Java and Functional) is an alternative way of configuring explicitly your Spring Boot application, different from regular auto-configuration, using a Java DSL. It is based on Spring Boot infrastructure, but used via functional bean definitions instead of JavaConfig.
An overview of JaFu DSL is provided below with the related API documentation. Be aware that a few static imports will be needed.
-
Go to start.spring.io
-
Select the latest Spring Boot
2.6.x
version -
Add the Spring milestone repository
https://repo.spring.io/milestone
-
Select the "Web" starter
-
Add the
org.springframework.fu:spring-fu-jafu:0.5.1
dependency -
Modify the generated
DemoApplication.java
file as following:
package com.sample;
import org.springframework.fu.jafu.JafuApplication;
import static org.springframework.fu.jafu.Jafu.webApplication;
import static org.springframework.fu.jafu.webmvc.WebMvcServerDsl.webMvc;
public class Application {
public static JafuApplication app = webApplication(a -> a.beans(b -> b
.bean(SampleHandler.class)
.bean(SampleService.class))
.enable(webMvc(s -> s
.port(s.profiles().contains("test") ? 8181 : 8080)
.router(router -> {
SampleHandler handler = s.ref(SampleHandler.class);
router
.GET("/", handler::hello)
.GET("/api", handler::json);
}).converters(c -> c
.string()
.jackson()))));
public static void main (String[] args) {
app.run(args);
}
}
See also sample projects here.