2016-11-07 2 views
0

私は春のコントローラー、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に印刷する方法はありますか?

+0

を解決/デバッグに役立つであろうすべてのコントローラのマッピングを、ログ/一覧表示することです。 http:// localhost:8080/<コンテキスト名>/employee – Khuzi

+1

このアプリケーションをどのように展開しましたか?それは.warファイルでしたか?または春のブート? .warの場合はcontextPath(.warの名前)も必要です。 'http:// localhost:8080//employee' – shazin

答えて

0

このSpringコントローラがフルURLに印刷する方法はありますか。 はマッピングされますか?

log4j.category.org.springframework.web=INFO 

、あなたのTomcat(または任意のサーバー)を再起動する場合は、スタートアップ時に、SpringコンテナがDispactherServletHandlerMappingを初期化するとき、それを:あなたは、ロギングプロパティの下に有効にすることができます

識別されたすべてのマッピング(さまざまなControllerクラスから)をログに出力し、Controllerクラスによってどのマッピングが提供されるかを実際に検証できるようにします。

P.S:このログは、ちょうどあなたのコンテキストは、あなたがヒットしているURLに欠けていると思われる問題

+0

私はこれを試してみるつもりです。うまくいけばそれは問題を解決するでしょう。 – pratiksanglikar

+0

問題を解決するのに役立つすべてのマッピングを一覧表示するのに役立ちます – developer

+0

このプロパティを有効にする方法? – pratiksanglikar

関連する問題