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。 - undefinedjersey
之后,它起作用了@ThomasAndolf。如果可能的话,请告诉我原因。 - undefined