Mic*_*ner 3 client resttemplate spring-hateoas hal-json
我想使用Traverson的Spring-Hateoas提供的休息服务,但是遇到以下问题,我在网络上找不到任何东西。我正在使用Spring-Boot 1.1.10.RELEASE。
我的客户呼叫如下所示:
...
final Traverson traverson = new Traverson(new URI("http://localhost:8080/bbsng-app-rest"), MediaTypes.HAL_JSON);
...
Run Code Online (Sandbox Code Playgroud)
我得到以下问题:
java.lang.NoClassDefFoundError: Could not initialize class org.springframework.hateoas.client.Traverson
at at.compax.bbsng.client.mvc.client.service.BerufServiceImpl.findeAlleBerufe(BerufServiceImpl.java:41)
at at.compax.bbsng.client.mvc.rest.controller.BerufController$1.call(BerufController.java:25)
at at.compax.bbsng.client.mvc.rest.controller.BerufController$1.call(BerufController.java:1)
at org.springframework.web.context.request.async.WebAsyncManager$4.run(WebAsyncManager.java:316)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.lang.Thread.run(Thread.java:745)
Run Code Online (Sandbox Code Playgroud)
=====
相关配置:
POM:
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
<version>1.1.0.RELEASE</version>
</dependency>
...
Run Code Online (Sandbox Code Playgroud)
应用类别:
@Configuration
@EnableHypermediaSupport(type = HAL)
@EnableAutoConfiguration
public class ApplicationClientMvc {
public static void main(final String[] args) {
SpringApplication.run(ApplicationClientMvc.class, args);
}
...
Run Code Online (Sandbox Code Playgroud)
====
调用上述URL时的Rest-Application响应:
{
"link": null,
"_links":
{
"self":
{
"href": "http://localhost:8080/bbsng-app-rest"
},
"berufe":
{
"href": "http://localhost:8080/bbsng-app-rest/beruf"
},
"betriebe":
{
"href": "http://localhost:8080/bbsng-app-rest/betrieb"
},
"fachrichtungen":
{
"href": "http://localhost:8080/bbsng-app-rest/fachrichtung"
}
}
}
Run Code Online (Sandbox Code Playgroud)
感谢您的帮助。
嗯,看来Spring-Hateoas需要额外的依赖关系Json-Path。
因此,将需要以下依赖项:
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2213 次 |
| 最近记录: |