2014-09-11 123 views
0

我在我的项目中使用Spring MVC,并将用户请求映射到URI时,出现404错误。但有其他控制器,我可以访问它。访问404错误的弹簧休息

工作控制器

@RequestMapping(value = "groupview.htm", method = RequestMethod.GET) 
    public String showGroups(
      @ModelAttribute("groupRegistrationDTO") GroupRegistrationDTO groupRegistrationDTO, 
      BindingResult result, Model model, 
      HttpServletRequest httpServletRequest) { 

GroupsResultDTO groupsResultDTO = manageGroupBusiness.getGroups(
       groupRegistrationDTO, result, model); 


return "showGroups"; 
} 

测试与Java类表示期望的输出

private static void wsRequest(String jsonInput) { 
     try { 

      URL url = new URL("http://localhost:5080/myservlet/groupview.htm"); 
      HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 
      conn.setRequestMethod("POST"); 
      conn.setRequestProperty("Accept","*/*"); 
      conn.setRequestProperty("Authorization", "Basic " 
        + getBasicAuthenticationEncoding()); 

      if (conn.getResponseCode() != 200) { 
       throw new RuntimeException("Failed : HTTP error code : " 
         + conn.getResponseCode()); 
      } 

      BufferedReader br = new BufferedReader(new InputStreamReader(
        (conn.getInputStream()))); 

      String output; 
      System.out.println("Output from Server .... \n"); 
      while ((output = br.readLine()) != null) { 
       System.out.println(output); 
      } 

      conn.disconnect(); 

     } catch (MalformedURLException e) { 

      e.printStackTrace(); 

     } catch (IOException e) { 

      e.printStackTrace(); 

     } 

    } 

现在我有另一个控制器,其是RESTful服务当我尝试测试使用海报插件或者通过java网络URL连接(使用requestmethod post)。我得到404响应代码。

试图通过网址访问:

http://localhost:5080/myservlet/authAndRegDevice.htm 

REST服务控制器

@RequestMapping(value = "authAndRegDevice.htm", method = RequestMethod.POST) 
@ResponseBody 
public String authenticateAndRegisterDevice(
     @RequestBody String notificationJsonRequest){ 

return "success"; 
} 

为什么会第二控制器给予404错误,而第一个工作。 有人可以帮我摆脱这个问题

+0

你发送一个JSON作为请求体,因为当你调用HTTP的第二个电话://本地主机:5080/myservlet/authAndRegDevice.htm?和;最后是那个偶然还是你调用同一个url? – shazin 2014-09-11 03:41:04

+0

你注册了第二种方法的bean控制器吗? – dieend 2014-09-11 04:00:49

+0

@shazin:是的,我发送的json输入作为请求正文我dint得到关于相同的URL的第二个问题 – pathfinder 2014-09-11 04:05:34

回答