【发布时间】:2016-10-31 11:02:36
【问题描述】:
我有一个 Spring MVC Web 应用程序。现在我想使用 Spring REST 将我的服务公开为 Web 服务。为此,我想根据 URL 值处理 Web 和 REST 请求。下面我对三个控制器进行了相同的尝试,MasterController、PatientController 和 PatientRESTController 如下所示。为简洁起见,已跳过方法。
@Controller("/")
public class MasterController {
@RequestMapping("/web")
public ModelAndView webApplication(){
return new ModelAndView("redirect:/web/patient");
}
@RequestMapping("/rest")
public ModelAndView webService(){
return new ModelAndView("redirect:/rest/patient");
}
}
@Controller("/web/patient")
public class PatientController {
@GetMapping("")
public ModelAndView patientHome(){
ModelAndView mv = new ModelAndView();
mv.setViewName("patienthome");
return mv;
}
}
@RestController("/rest/patient")
public class PatientRESTController {
@GetMapping("")
public List getAllPatientsREST(){
return patientService.findAll();
}
}
在启动我的 Web 应用程序时出现错误:
模糊映射。无法映射“/rest/patient”方法 公共 java.util.List PatientRESTController.getAllPatientsREST() to {[],methods=[GET]}: 已经有 '/web/patient' bean 方法
如何为我的 REST 和 Web 应用程序创建不同的 url 映射?
【问题讨论】:
标签: java spring rest spring-mvc request-mapping