【发布时间】:2020-08-24 04:10:44
【问题描述】:
我必须使用 spring Webflux 以反应方式保存一些值。但是当我发送请求时,会返回 404 状态作为响应。
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
EmpController 类
@RestController
@RequestMapping("/emp")
public class EmpController {
private EmployeeRepository empRepo;
@Autowired
public EmpController(EmployeeRepository empRepo)
{
this.empRepo=empRepo;
}
@PostMapping("/save")
@Consumes({MediaType.APPLICATION_JSON})
public void saveEmp(@RequestBody Mono<Employee> emp)
{
emp.subscribe(e-> {
e.setDate(new Date());
empRepo.saveEmp(e);
});
}
}
当我通过 PostMan 发送请求时,返回 404(未找到)。
【问题讨论】:
-
确保您的
EmpController在@ComponentScan下关注。如果您没有放置任何@ComponentScan,请确保您已将文件放置在您的main()所在的相同或子包下。您可以在此处分享您的项目结构以进一步了解或创建 GitHub 存储库并分享 URL。 -
@Vipul Kumar 在这里 Github repo 链接github.com/Benzeman97/reactive-async-app.git
-
jersey 依赖是unneded。春天不使用球衣
-
删除
jersey@ThomasAndolf 后它工作了。如果可能,请告诉我原因
标签: java spring spring-boot reactive-programming spring-webflux