gpt4 book ai didi

java - Spring RestTemplate NoClassDefFoundError

转载 作者:行者123 更新时间:2023-11-30 03:30:28 24 4
gpt4 key购买 nike

在使用 Spring restTemplate 执行以下代码时出现 NoClassDefFoundError messageConverters.add(new MappingJackson2HttpMessageConverter());

我错过了什么?

    RestTemplate restTemplate = new RestTemplate();
List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
messageConverters.add(new MappingJackson2HttpMessageConverter());
restTemplate.setMessageConverters(messageConverters);
ResponseEntity<String> responseEntity = restTemplate
.exchange(
"https://abc.stuff.com/abd",
HttpMethod.GET, requestEntity, String.class);

error:
exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper
at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.<init>(MappingJackson2HttpMessageConverter.java:62)

最佳答案

您可能缺少 Jackson 依赖项。如果您使用maven,则可能需要添加此内容。

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.databind-version}</version>
</dependency>

您还可以引用以下链接以获取完整的依赖项。

http://www.journaldev.com/2552/spring-restful-web-service-example-with-json-jackson-and-client-program

关于java - Spring RestTemplate NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29158563/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com