Spring Applications
Exercise: Todo REST Client
- Add the Maven dependencies
org.springframework:spring-web
, com.fasterxml.jackson.core:jackson-databind
and com.fasterxml.jackson.datatype:jackson-datatype-jsr310
to the todo application.
- Remove the repository and the JPA annotations from the
Todo
class and rename the TodoService
class into TodoListProxy
.
- Inject the Spring
RestTemplateBuilder
into the proxy and use it to create RestTemplate
object.
- Use the template to re-implement the proxy methods which send REST requests to the web service (see API Documentation).
- In the
findTodo
and updateTodo
methods catch the HttpClientErrorException.NotFound
exception and rethrow a TodoNotFoundException
.
Solution