Spring JAX-RS proxy clients

This is a piece of software that I had written a quite time ago, although just recently I though that it would nice idea to refactor it and share through github project. The base idea is simple: have a auto discovered (through classpath scaning) Spring JAX-RS proxy client beans.

I’m aware that Spring Cloud Netflix together with Netflix Feign clients will bring you almost the same functionality with additional support for autodiscovery (through Eureka, Consul or Zookeper) and client loadbalancing (thanks to Ribbon) although the extension itself does not try to compete in this area and was though as just simple consumption of the remote JAX-RS service.

JAX-RS 2.0 brought the client API giving a standarized way to consume the service on the client side. Though, when working with large enterprise scale systems such low level request handling, tends to become very verbose with a lot of boilerplate code. This is why he have shifted to proxy based clients, despite the fact that those were supported even before JAX-RS 2.0. The proxy based clients have another advantages, there are statically typed and define “contract” of the service that in case of any changes are very simple to track down.

Not mentioning the Spring Cloud project, Spring Framework was lacking any support for autodiscovering and registering the JAX-RS annotated interfaces, so I had end up in writting my own solution for that. Setup is really simple, requires only adding the library to the classpath and specify the root url of your REST service.


To enable the proxies just add fallowing annotation to your Spring `@Configuration` class.

    basePackages = "com.app.rest.api",
    serviceUrl = "localhost:8080/api"
public class AppConfig {

This is going to grab every single @Path annotated interface that is able to find and turns it into a JAX-RS proxy client. Which you can simply inject similar to any other Spring bean.

At the moment it offers a bit of flexibility, you can use it either with RESTEasy, CXF and Jersey as your JAX-RS providers, though keep in mind that they differ in terms of capabilities for proxy based clients.

You can find any additional details and more examples on the Github project page: https://github.com/jmnarloch/spring-jax-rs-client-proxy

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s