Configuring Jersey Declarative Linking in Bootique

In my previous post we talked about creating custom REST links with Jersey Declarative Linking. Configuring it for Bootique is extremely simple, but it's different than the Jersey Documentation on configuring it in a typical JAX-RS Application. 

First, here's the Package Info you'll need in your POM for Jersey Declarative Linking.

<dependency>
    <groupId>org.glassfish.jersey.ext</groupId>
    <artifactId>jersey-declarative-linking</artifactId>
    <version>${jersey-links.version}</version>
</dependency>

The Jersey User Guide (section 13.10) tells you to do something like the following, defining and registering your package for Declarative Linking support.

// Create JAX-RS application.

final Application application = new ResourceConfig()
        .packages("org.glassfish.jersey.examples.linking")
        .register(DeclarativeLinkingFeature.class);

This is where the confusion might come in for Bootique Users, since we're adding Declarative Linking to our Bootique Jersey Module configuration, not a straight-up JAX-RS application. Turns out adding it is a snap! No package declaration or registration required. Simply add the DeclarativeLinkingFeature class as a Bootique Jetty Module Feature and you're good to go!

@Override
public void configure(Binder binder) {

    JerseyModule.extend(binder)
            .addResource(UserResource.class)
            .addResource(GeneralResource.class)
            .addFeature(DeclarativeLinkingFeature.class);

    binder.bind(IConnection.class).to(MySqlConnection.class);
}

Source Code Notes for this Post

Source code discussed in this post is found in NixMash Microservices on GitHub. Code for this particular post is found in branch microservices-v0.1.0 - Initial Layout and Structure.

More Like This Post