Я пытаюсь сделать простой REST сервис, но столкнулся с 2 проблемами.
1. Любой метод контроллера REST возвращает ошибку 406 http;
@GetMapping(value = "/getUser/{id}", headers = "Accept=application/json",
produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseBody
public ResponseEntity<Object> getUser(@PathVariable(value = "id")Long id) {
if (id == null) return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
UserInfo userInfo = userService.get(id);
if (userInfo == null) return new ResponseEntity<>(HttpStatus.NOT_FOUND);
return new ResponseEntity<>(userInfo, HttpStatus.OK);
}
@GetMapping(value = "/getUsers", headers = "Accept=application/json",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public List<UserInfo> getUsers()
{
return userService.getAll();
}
Итак, Google сказал мне, что проблема может быть в отсутствующих зависимостях Jackson2.
Но добавление этих зависимостей вызывает эту ошибку, добавление младших версий приводит либо к тому же выводу, либо к 406
.
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.4.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.4.4</version>
</dependency>
> 06-May-2018 15:36:45.477 WARNING [http-nio-25565-exec-3]
> org.springframework.context.support.AbstractApplicationContext.refresh
> Exception encountered during context initialization - cancelling
> refresh attempt:
> org.springframework.beans.factory.BeanCreationException: Error
> creating bean with name 'requestMappingHandlerAdapter' defined in
> class path resource
> [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]:
> Bean instantiation via factory method failed; nested exception is
> org.springframework.beans.BeanInstantiationException: Failed to
> instantiate
> [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]:
> Factory method 'requestMappingHandlerAdapter' threw exception; nested
> exception is java.lang.NoClassDefFoundError:
> com/fasterxml/jackson/databind/exc/InvalidDefinitionException
Что я делаю не так?