The UndertowJaxrsSpringServer


#undertow #spring


Recently I’m working on migrating resteasy-spring tests to use the Undertow container. Before these tests were using the TJWS embedded container.


As resteasy-tjws container is deprecated in master, so there is some work to be done to make undertow container to load the resteasy-spring components correctly.


In order to achieve the goal, I created a new module called resteasy-undertow-spring, and it contains a single class called UndertowJaxrsSpringServer.


This server class will accept the spring xml configuration file, and load the configured spring context beans into spring provided org.springframework.web.servlet.DispatcherServlet. Here is the relative code in UndertowJaxrsSpringServer:



In addition, the resteasy-spring module contains a default xml configuration file called springmvc-resteasy.xml, and it can be used by default to setup the resteasy-spring component properly.


So users just need to prepare their own spring config file and include the springmvc-resteasy.xml to load the resteasy-spring module. Here is a minimal example of the config:



In above config, we can see it includes the springmvc-resteasy.xml provided by resteasy-spring module, and it will scan the org.jboss.resteasy.springmvc.test package to include the user-written jaxrs resources.


And here is the code to setup the UndertowJaxrsSpringServer and start it:



The above code is part of the tests in resteasy-undertow-spring, and the tests can be used as usage example:


Resteasy/ at master · resteasy/Resteasy · GitHub


And the tests shows more advanced spring configurations that can be used as reference.