Spring Resfull错误HTTP状态500

时间:2015-09-15 11:56:08

标签: spring-mvc

我尝试构建spring restfull服务教程,这是我的代码:

的web.xml

<servlet>
    <servlet-name>accounts</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>
                /WEB-INF/mvc-config.xml
                /WEB-INF/app-config.xml
            </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>accounts</servlet-name>
    <url-pattern>/app/*</url-pattern>
  </servlet-mapping>

这是我的控制者:

@Controller
public class AccountController {
@RequestMapping(value = "/accounts", method = RequestMethod.GET, produces = {"application/json"})
    @ResponseStatus(HttpStatus.OK)
    public List<Account> accountSummary() {
        return accountManager.getAllAccounts();
    }
}

当我使用网址打开浏览器时:http://localhost:8080/rest-ws/app/accounts 我收到了这个错误:

javax.servlet.ServletException: Circular view path [accounts]: would dispatch back to the current handler URL [/rest-ws/app/accounts] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)

我想念什么?

1 个答案:

答案 0 :(得分:1)

试试这个:

@Controller
@RequestMapping(value = "/accounts")
public class AccountController {
    @RequestMapping(value = "/list", 
         method = RequestMethod.GET, produces = {"application/json"})
    @ResponseStatus(HttpStatus.OK)
    public List<Account> accountSummary() {
         return accountManager.getAllAccounts();
    }
}

打开:

http://localhost:8080/rest-ws/app/accounts/list

有用吗?