私は春のコントローラー、Springコントローラがマップする完全なURLを知る方法はありますか?
@Controller
@RequestMapping(value = "/employee")
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
/**
* returns all the employees in the datastore.
*
* @return list of all employees.
*/
@RequestMapping(method = RequestMethod.GET)
public @ResponseBody String getAllEmployees() {
return convertObjectListToJSONArray(this.employeeService.listEmployees());
}
/**
* adds an employee in the data-store.
*
* @param employee
* employee to add in the data-store.
* @return request status.
*/
@ResponseStatus(value = HttpStatus.CREATED)
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public ResponseEntity<?> addEmployee(UriComponentsBuilder uriCBuilder, @RequestBody Employee employee) {
Employee e = this.employeeService.getEmployeeById(employee.getId());
if(null != e) {
throw new EmployeeConflictException();
}
this.employeeService.addEmployee(employee);
UriComponents uriComponents = uriCBuilder.path("/cmpe281Pratik021/rest/employee/{id}")
.buildAndExpand(employee.getId());
HttpHeaders headers = new HttpHeaders();
headers.setLocation(uriComponents.toUri());
return new ResponseEntity<Void>(headers, HttpStatus.CREATED);
}
を持っている。しかし、私はhttp://localhost:8080/employeeを打ったとき、それはエラー404 を与えるが、この春コントローラがマップされようとしている完全なURLに印刷する方法はありますか?
を解決/デバッグに役立つであろうすべてのコントローラのマッピングを、ログ/一覧表示することです。 http:// localhost:8080/<コンテキスト名>/employee – Khuzi
このアプリケーションをどのように展開しましたか?それは.warファイルでしたか?または春のブート? .warの場合はcontextPath(.warの名前)も必要です。 'http:// localhost:8080//employee' –
shazin