我想使用0.19.0.RELEASE
的最新稳定版Spring HATEOAS
。我将其与1.2.6.RELEASE
的最新稳定版Spring Boot
结合使用。在我们找到的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:...)
看起来很糟糕,但我们可以翻译它。一方面,org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration
spring-boot-autoconfigure-1.2.6.RELEASE.jar
我们找到
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
的两个参数Constructor。另一方面,在Jackson2HalModule.HalHandlerInstantiator
的{{1}}中,构造函数不幸只有3或4个参数:
spring-hateoas-0.19.0.RELEASE.jar
我尝试过较新的,不稳定的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
,因为在这种情况下会发生其他错误。
您知道是否有任何解决方法?
答案 0 :(得分:1)
我正在使用list.toArray(new Person[list.size()]);
1.2.5.RELEASE
而没有任何错误。升级了一些像这样的依赖:
0.19.0.RELEASE
答案 1 :(得分:0)
似乎你有spring-hateoas
个罐子的多个版本,这是我的依赖配置。
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