SAP Hybris控制器调用URL时出现服务器错误求助
SAP Hybris 服务器错误排查:/custid 调用失败
问题背景
练习Hybris基础流程时,访问/custid触发500服务器错误,DAO层执行查询时出错(原问题附报错截图)。
代码片段
控制器代码
@Controller public class NewCustomerController { @RequestMapping(value = "/custid", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public String getCustomerNameFromCustId(@RequestBody final Model model){ final List<NewCustomerData> nameList = newCustomerFacade.getCustomerNamefromID(); model.addAttribute("nameList",nameList); return ControllerConstants.Views.Pages.NewCustomer.CustId; } }
JSP页面(custid.jsp)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="" tagdir="" %> <html> <head> <title>Customer ID detail</title> </head> <body> <h1>This page displays the name of the customer based on customer ID</h1> <h3>The name of the customer is ${nameList}.<h3> </body> </html>
关键错误点及修复方案
控制器参数注解错误
@RequestBody不能用于Model参数:GET请求无请求体,该注解会强制解析请求体,直接抛出HttpMessageNotReadableException。移除该注解,方法签名改为:public String getCustomerNameFromCustId(final Model model)produces = MediaType.APPLICATION_JSON_VALUE与返回视图冲突:控制器返回JSP视图(HTML),但声明返回JSON,响应头与实际内容不匹配,引发容器错误。删除该produces参数即可。
JSP标签库配置无效
<%@ taglib prefix="" tagdir="" %>是非法配置,无实际意义,直接删除该行。若需使用JSTL或Hybris标签,补充正确配置,例如:<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
DAO层查询问题
- 查看Hybris核心日志(
hybris/log/console.log或tomcat/localhost.log),提取DAO层的错误栈:- 检查SQL语句是否存在表/字段拼写错误
- 确认DAO类是否被正确注入,
newCustomerFacade实例是否初始化完成 - 验证数据库连接配置,确保Hybris能正常访问数据库
- 查看Hybris核心日志(
视图路径验证
- 确认
ControllerConstants.Views.Pages.NewCustomer.CustId对应的JSP路径正确,文件需存在于web模块的WEB-INF/views目录下(如yourstorefront/web/webroot/WEB-INF/views/pages/newCustomer/custid.jsp)
- 确认
修复优先级
先修正控制器的注解错误,这是触发服务器错误的直接原因;再处理JSP配置问题;最后根据日志定位DAO层的查询错误。
内容的提问来源于stack exchange,提问作者user19030239
相关产品推荐
相关产品推荐

