我試着去擊中門柱控制器:休息控制器給予404
@Controller
public class CustomerController
{
private static Logger LOG = Logger.getLogger(CustomerController.class);
@Resource(name = "lookupAddressClient")
private LookupAddressClient lookupAddressClient;
@Autowired
private HssCustomerFacade customerFacade;
private final RequestMappingHandlerMapping handlerMapping;
@Autowired
public CustomerController(final RequestMappingHandlerMapping handlerMapping)
{
this.handlerMapping = handlerMapping;
}
@RequestMapping(value = "/endpointdoc", method =
{ RequestMethod.GET, RequestMethod.POST })
public void show(final Model model)
{
model.addAttribute("handlerMethods", this.handlerMapping.getHandlerMethods());
}
@Resource(name = "hssB2BCommerceUserFacade")
protected HssB2BCommerceUserFacade hssB2BCommerceUserFacade;
private static final String ERROR_MSG = "##### Error in HssB2BCommerceUserFacade.getUserdetailsForHSSTraining()-->";
private static final String ERROR_MSG_END = "####";
/* TODO: Need to move this controller to hsscommercewebservice once fix the hsscommerce webservice url issue fixed */
@RequestMapping(value = "/webservice/userDetails", method =
{ RequestMethod.POST }, headers = "Accept=*/*")
public @ResponseBody HSSUserData getUserDetails(@RequestBody final UserCredentials userCredentials,
final HttpServletResponse response)
{
....
}
凡getUserDetails()是方法。
的UserCredentials:
public class UserCredentials {
private String userId;
private String password;
/**
* @return the userId
*/
public String getUserId() {
return userId;
}
/**
* @param userId the userId to set
*/
public void setUserId(String userId) {
this.userId = userId;
}
/**
* @return the password
*/
public String getPassword() {
return password;
}
/**
* @param password the password to set
*/
public void setPassword(String password) {
this.password = password;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "UserCredentials [userId=" + userId + ", password=" + password
+ "]";
}
Im using PostMan client:
我打的網址:https://localhost:8011/webservice/userDetails
我的頭:接受=應用程序/ JSON 內容類型=應用程序/ JSON
我的JSON身在請求:
{
"userCredentials": {
"userId": "asdnasd",
"password": "nasdkask"
}
}
我得到40 4,並且不管我傳遞什麼請求,該請求映射都不會觸發。控制器正在與其他映射「/ endpointdoc」一起工作。 控制檯中沒有錯誤。
請指教。
有沒有理由你有'header =「Accept = */*」'? 怎麼樣: '@PostMapping(「/ webservice/userDetails」)' – Ben
我很困惑什麼應該是我的接受價值。所以我將它設置爲*/*並在Postman中將值設置爲應用程序/ json –
我相信這就是爲什麼你會得到404,RequestMapping使用'header'字段來幫助確定應該調用哪個映射,它不匹配字符串'*/*'。如果你想具體聲明它匹配應用程序JSON,使用: '@PostMapping(value =「/ webservice/userDetails」,consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)' – Ben