java - Spring:Spring HATEOAS 0.19.0 的哪个 Spring Boot 版本?

标签 java spring spring-boot spring-hateoas

我想使用 Spring HATEOAS 的最新稳定版本 0.19.0.RELEASE。我将它与 Spring Boot 的最新稳定版本 1.2.6.RELEASE 相结合。在 build.gradle 中我们发现了其他

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'
}

当我启动主应用程序时,出现异常

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:...)

这看起来很糟糕,但我们可以翻译它。一方面,在spring-boot-autoconfigure-1.2.6.RELEASE.jarorg.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration中我们发现

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);
                ...

这意味着 Jackson2HalModule.HalHandlerInstantiator 的两个参数构造函数被调用。另一方面,在 spring-hateoas-0.19.0.RELEASE.jarJackson2HalModule.HalHandlerInstantiator 中,遗憾的是构造函数只有 3 或 4 个参数:

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

我尝试了更新的、不稳定的 Spring Boot 版本,但这也不起作用。我不想使用较低版本的 Spring HATEOAS,因为在这种情况下会发生其他错误。

您知道是否有任何解决方法吗?

最佳答案

我正在使用 1.2.5.RELEASE0.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>

关于java - Spring:Spring HATEOAS 0.19.0 的哪个 Spring Boot 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32719001/

相关文章:

java | Gson |将 JSON 对象添加到现有的 JSON 文件

java - 无法从 PMD 中排除某些规则

java - 在java spring boot中减少另一个表中的列的值

java - 如何在java spring boot web应用程序中分配目录级别用户访问权限

java.sql.SQLException : Field foreign_key doesn't have a default value

java - 将在一台服务器上正常工作的 Tomcat 6 webapp 复制到另一台 Tomcat 6 服务器,得到 Null 组件错误

java - 用于在 Eclipse 中查找并用 ArrayList<> 替换所有 ArrayList<something> 的正则表达式

java - 为什么 JSTL 格式数字模式 #00.00 不显示 $0.00 而是显示 $1,356.00?

java - 如何使用 Spring AOP 和 WebFlux 获取从 joinPoint.proceed() 返回的对象

java - 二级缓存永不命中using、spring3、hibernate4、ehcache?