我正在使用Spring REST API端點創建Spring引導服務。但我陷入了一個非常簡單的休息電話。我休息控制器如下:Spring REST端點:404請求的資源不可用
@RestController
@RequestMapping(value={"/reportservice"})
public class ReportingMessageController {
@Autowired
private ReportService reportService;
@RequestMapping(value = {"/reports" }, method = RequestMethod.GET, produces = {
MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
public ResponseEntity<ResponseMessage> getReport(@RequestParam(value="eaid", required=true) String eaid,
@RequestParam(value="source", required=false) String source,
@RequestParam(value="userid", required=false) String userid,
@RequestParam(value="org", required=false) String org,
@RequestParam(value="startdate", required=true) Date startDate,
@RequestParam(value="enddate", required=true) Date endDate,
@RequestParam(value="page", required=false) int pageid){
ReportQueryParams params = new ReportQueryParams();
params.setEaid(eaid);
params.setSid(sid);
params.setSource(source);
params.setUserid(userid);
params.setOrg(org);
params.setStartdate(startDate);
params.setEnddate(endDate);
params.setPageid(pageid);
System.out.println(params);
ResponseMessage response = reportService.getReports(params);
return new ResponseEntity<ResponseMessage>(response, HttpStatus.OK);
}
}
服務類:
@Component
public class ReportService {
public ResponseMessage getReports(ReportQueryParams params){
return new ResponseMessage();
}
}
ResponseMessage類是簡單的POJO
我的URI是
http://localhost:8080/reportservice/reports?eaid=6764623946&source=ABC&userid=abhattacherji&org=trpo&startdate=8/11/2016&enddate=9/1/2016&page=1
和我得到HTTP狀態404錯誤。即使我忽略查詢參數,第一部分(/ reportservice/reports)也不起作用。任何潛在客戶都會有幫助。提前致謝。
您是否在Web服務器中爲您設置了任何上下文路徑? –
你可以發佈你提出請求的部分,至少發佈生成url的部分, – Priyamal
@Priyamal,我從郵遞員來調用它。確切地說,我用Accept標頭髮布的URI作爲Application/xml和Application/json –