gpt4 book ai didi

spring - 无法写入 HTTP 消息 : org. springframework.http.converter.HttpMessageNotWritableException:找不到类型返回值的转换器:

转载 作者:行者123 更新时间:2023-12-01 09:46:38 24 4
gpt4 key购买 nike

我正在尝试公开 REST 服务,但是当我从 POSTMAN 访问它时,我在下面:

警告:无法写入 HTTP 消息:org.springframework.http.converter.HttpMessageNotWritableException:找不到类型返回值的转换器:类 java.util.ArrayList

因为我还包含了以下所需的 jar 文件:

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.1</version>
</dependency>

这是我的 REST Controller 代码:

@RestController
@RequestMapping("/MayankAPI")
public class TestRestAPI {
@RequestMapping(value="/sayHello" , method = RequestMethod.POST)
public TestPojo postData(@RequestBody String payload) {
System.out.println("Hello post"+payload);
TestPojo payload1=new TestPojo();
payload1.setStudentName("Jack");
return payload1;
}
@RequestMapping(value="/sayHello" , method = RequestMethod.GET)
public List<TestPojo> getData(String payload) {
System.out.println("Hello get"+payload);
List<TestPojo> payload1=new ArrayList<TestPojo>();
TestPojo tp = new TestPojo();
tp.setStudentName("Jack");
payload1.add(tp);
return payload1;
}

这是我要归还的 bean :

public class TestPojo {

private String studentName;
private String studentId;

public String getStudentName() {
return studentName;
}

public void setStudentName(String studentName) {
this.studentName = studentName;
}

public String getStudentId() {
return studentId;
}

public void setStudentId(String studentId) {
this.studentId = studentId;
}
}

请帮助我哪里做错了。

最佳答案

我知道为时已晚,但仍然替代解决方案:您需要将 Spring 项目启用为 Web MVC,如下所示:

@配置
@EnableWebMvc
@ComponentScan("basePackages = com.test")
公共(public)类 MiBenefitConfiguration
{
}

关于spring - 无法写入 HTTP 消息 : org. springframework.http.converter.HttpMessageNotWritableException:找不到类型返回值的转换器:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47315106/

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