【问题标题】:ResponseBody cannot be resolved to a typeResponseBody 无法解析为类型
【发布时间】:2011-08-07 22:23:07
【问题描述】:

我正在尝试在我的控制器中编写此方法:

    @ResponseBody
@RequestMapping(value = {"/getTeams"}, method = RequestMethod.GET)
public void getMaxRequestSize(HttpServletResponse response) {
    String autoCompleteList = null;
    List<Team> teams = atService.getAllTeams();
    Iterator itr = teams.iterator();
    while (itr.hasNext()) {
        autoCompleteList += itr.next().toString() + "\n";
    }
    response.setContentType("text/html");
    PrintWriter writer;
    try {
        writer = response.getWriter();
        writer.write(autoCompleteList);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

由于某种原因,我总是在 ResponseBody 注释上遇到错误(= 无法解析为类型)。我google了很久,没有找到解决办法。我敢肯定这很傻。我可以毫无问题地使用所有其他注释...

【问题讨论】:

    标签: model-view-controller spring annotations controller response


    【解决方案1】:

    这是一个 Maven 项目吗?您最终可能会在您的 war 文件中使用旧的 Spring 2.5.6 jar,而不是 Spring 3。Eclipse 的 POM 编辑器的 Dependency Hierarchy 选项卡可以帮助您确定是否是这种情况。

    【讨论】:

    • 我使用的是过时的 Spring 版本。我无权升级到新版本,因为我必须使用 2.5.6... 有什么办法可以解决这个问题?
    • 无论如何都要使用 Spring 3 并告诉他们它是 2.5.6... 它意味着向后兼容 ;-) 说真的,您可能只是无法使用该注释。 2.5.6 (static.springsource.org/spring/docs/2.5.x/reference/index.html) 的参考文档怎么说?
    猜你喜欢
    • 2019-10-09
    • 2015-10-22
    • 1970-01-01
    • 2021-08-28
    • 2013-12-14
    • 2015-06-10
    • 2015-11-22
    • 1970-01-01
    • 2014-07-23
    相关资源
    最近更新 更多