My main aim is to set up Redhat's Undertow embedded in my app without any web.xml
and without Spring Boot. Undertow looks like it's close enough to a servlet container to fulfill my requirements and at the same time super-performant and lean. As far as other microframeworks go, I also looked at SparkJava but am trying out Undertow first because its docs look better.
So Undertow sounds great but all the docs and tutorials I come across stop after returning "Hello World" on /
. Perhaps the best I could find is StubbornJava/RestServer.java where all the endpoints are hard-coded, e.g.:
public static final RoutingHandler ROUTES = new RoutingHandler()
.get("/users", timed("listUsers", UserRoutes::listUsers))
What I can't find is anything showing how or if it's even possible to link up the Spring MVC / REST controller annotations with the basic Undertow structure.
I already have an app with a set of endpoints defined in Spring annotations.
I have a big piece missing from my knowledge of Spring and Undertow about how to combine the two, but I can see from Baeldung / Configuring Spring Boot that Spring provides a way to use Undertow in Boot. I just don't need Spring Boot. And I'm really not enthusiastic about digging into the Spring source to see how Pivotal did it, since it probably won't be replicable in my situation. This is the way to implement it in Boot:
@Bean
public UndertowEmbeddedServletContainerFactory embeddedServletContainerFactory() {
UndertowEmbeddedServletContainerFactory factory =
new UndertowEmbeddedServletContainerFactory();
factory.addBuilderCustomizers(new UndertowBuilderCustomizer() {
@Override
public void customize(io.undertow.Undertow.Builder builder) {
builder.addHttpListener(8080, "0.0.0.0");
}
});
return factory;
}
My guess is that I'd have to programmatically grab the annotated Spring REST controllers and create the required Undertow resources for each.
It seems like the Undertow mailing list is unsearchable too.