У меня есть Spring Controller,Есть ли способ узнать, какой полный URL-адрес контроллер Spring собирается отобразить?
@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, который весной этого года контроллер будет отображаться?
Это кажется ваш контекст отсутствует в URL вы ударяя. http: // localhost: 8080//employee –
Khuzi
Как вы развертывали это приложение? это был файл .war? или Spring Boot? Если вам нужна .war, вам понадобится contextPath (имя .war). 'http: // localhost: 8080//employee' –
shazin