Spring: Spring boot version for Spring HATEOAS 0.19.0?

I want to use the latest stable version 0.19.0.RELEASE Spring HATEOAS. I combine it with the latest stable version 1.2.6.RELEASE Spring Boot. In build.gradlewe 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 launch the main application, I get an 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:...)

It looks awful, but we can translate it. On the one hand, in org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfigurationof spring-boot-autoconfigure-1.2.6.RELEASE.jarwe 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);
                ...

This means that two constructor arguments are Jackson2HalModule.HalHandlerInstantiatorcalled. On the other hand, Jackson2HalModule.HalHandlerInstantiatorof spring-hateoas-0.19.0.RELEASE.jarconstructors, unfortunately, there are only 3 or 4 of the argument:

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 tried newer, not stable versions Spring Boot, but this will not work either. I do not want to use a lower version Spring HATEOAS, because in this case other errors occur.

, ?

+4
2

1.2.5.RELEASE 0.19.0.RELEASE - . :

<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>
+1

, spring-hateoas jars. , .

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'

Maven central spring-boot-starter-hateoas:1.2.6.RELEASE spring-hateoas 0.19.0

0

Source: https://habr.com/ru/post/1608500/


All Articles