Johannes Flügel
Johannes Flügel

Reputation: 3262

Spring: which Spring Boot version for Spring HATEOAS 0.19.0?

I want to use the latest stable version 0.19.0.RELEASE of Spring HATEOAS. I combine it with the latest stable version 1.2.6.RELEASE of Spring Boot. In the build.gradle we find among others

apply plugin: 'spring-boot'
...
dependencies {
    compile("org.springframework.boot:spring-boot-starter-web:1.2.6.RELEASE")
    compile 'org.springframework.hateoas:spring-hateoas:0.19.0.RELEASE'
}

When I start the main application, I get the exception

Exception in thread "main" org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'org.springframework.boot.autoconfigure.hateoas.
HypermediaAutoConfiguration$HypermediaConfiguration$HalObjectMapperConfiguration': 
Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: 
org.springframework.hateoas.hal.Jackson2HalModule$HalHandlerInstantiator.<init>
(Lorg/springframework/hateoas/RelProvider;Lorg/springframework/hateoas/hal/CurieProvider;)V
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136)
    ...
    at ... Application.main(Application.java:...)

That looks terrible, but we can translate it. On the one hand, in org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration of spring-boot-autoconfigure-1.2.6.RELEASE.jar we find

public class HypermediaAutoConfiguration {
    ...
    protected static class HypermediaConfiguration {
        ...
        protected static class HalObjectMapperConfiguration {
            ...
            private void registerHalModule(ObjectMapper objectMapper) {
                ...
                Jackson2HalModule.HalHandlerInstantiator instantiator = new Jackson2HalModule.HalHandlerInstantiator(
                        HalObjectMapperConfiguration.this.relProvider,
                        HalObjectMapperConfiguration.this.curieProvider);
                ...

That means the two argument Constructor of Jackson2HalModule.HalHandlerInstantiator is called. On the other hand, in Jackson2HalModule.HalHandlerInstantiator of spring-hateoas-0.19.0.RELEASE.jar the constructors unfortunately have only 3 or 4 arguments:

public class Jackson2HalModule extends SimpleModule {
    ...
    public static class HalHandlerInstantiator extends HandlerInstantiator {

        ...
        public HalHandlerInstantiator(RelProvider resolver, CurieProvider curieProvider,
                MessageSourceAccessor messageSource) {
            ...
        }

        public HalHandlerInstantiator(RelProvider resolver, CurieProvider curieProvider,
                MessageSourceAccessor messageSource, boolean enforceEmbeddedCollections) {
            ...
        }
        //no further constructors

I have tried newer, not stable Spring Boot versions, but this does not work, either. I don't want to use a lower version of Spring HATEOAS, because in this case other errors occur.

Do you know if there is any workaround?

Upvotes: 4

Views: 2343

Answers (2)

Lovababu Padala
Lovababu Padala

Reputation: 2477

It seems you have multiple versions of spring-hateoas jars, Here is dependency configuration i have.

compile ("org.springframework.boot:spring-boot-starter-hateoas:1.2.6.RELEASE"){
exclude module: 'spring-hateoas'
} 
compile 'org.springframework.hateoas:spring-hateoas:0.19.0.RELEASE'

And as per Maven central spring-boot-starter-hateoas:1.2.6.RELEASE compile dependency, should work with updated spring-hateoas 0.19.0

Upvotes: 0

&#193;kos Ratku
&#193;kos Ratku

Reputation: 1421

I am using 1.2.5.RELEASE with 0.19.0.RELEASE without any errors. Upgraded a few dependencies like this :

<properties>
        <spring-data-releasetrain.version>Gosling-RELEASE</spring-data-releasetrain.version>
        <spring-hateoas.version>0.19.0.RELEASE</spring-hateoas.version>
        <jackson.version>2.6.1</jackson.version>
</properties>

Upvotes: 2

Related Questions