报告结构:
main report - myreport.jrxml
sub report - myreport_detail.jrxml
使用子报表运行我的主报表在Jasper Report Studio中运行正常。在我的Spring Boot环境中,我使用JasperReportsPdfView。
但是在这里运行myreport.jrxml我得到:
Caused by: net.sf.jasperreports.engine.JRException: Resource not found at: jasper/repo/myreport_detail.jasper.
at net.sf.jasperreports.repo.RepositoryUtil.getResourceFromLocation(RepositoryUtil.java:153)
at net.sf.jasperreports.repo.RepositoryUtil.getReport(RepositoryUtil.java:112)
at net.sf.jasperreports.engine.fill.JRFillSubreport.loadReport(JRFillSubreport.java:411)
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateReport(JRFillSubreport.java:378)
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateSubreport(JRFillSubreport.java:440)
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluate(JRFillSubreport.java:354)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:383)
at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:506)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2412)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:761)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:240)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:99)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:607)
at net.sf.jasperreports.engine.fill.BaseReportFiller.fill(BaseReportFiller.java:387)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:109)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:456)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:863)
at org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView.doFillReport(AbstractJasperReportsView.java:702)
at org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView.fillReport(AbstractJasperReportsView.java:669)
at org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView.renderMergedOutputModel(AbstractJasperReportsView.java:566)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1271)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
... 97 common frames omitted
注意:运行一个没有子报告的单个报告可以正常工作
端点:
@RequestMapping(value = "/api", params = {"dir", "name"})
public ModelAndView report(
HttpServletRequest request,
@RequestParam(value = "dir") String dir,
@RequestParam(value = "name") String name) throws Exception {
JasperReportsPdfView view = new JasperReportsPdfView();
view.setJdbcDataSource(dataSource);
view.setUrl("classpath:jasper/" + dir + "/" + name + ".jrxml");
view.setApplicationContext(context);
view.setHeaders(getProperties(name, false));
return new ModelAndView(view, getParameters(request));
}
Java代码崩溃RepositoryUtil:
public <K extends Resource> K getResourceFromLocation(String location, Class<K> resourceType) throws JRException
{
K resource = null;
List<RepositoryService> services = getServices();
if (services != null)
{
for (RepositoryService service : services)
{
resource = service.getResource(location, resourceType);
if (resource != null)
{
break;
}
}
}
if (resource == null)
{
throw
new JRException(
EXCEPTION_MESSAGE_KEY_RESOURCET_NOT_FOUND,
new Object[]{location}); //FIXMEREPO decide whether to return null or throw exception; check everywhere
}
return resource;
}
错误行:
resource = service.getResource(location, resourceType);
变量:
location -> jasper/repo/myreport_detail.jasper
resourceType -> class net.sf.jasperreports.repo.ReportResource
抛出异常行,因为resource = null:
public static final String EXCEPTION_MESSAGE_KEY_RESOURCET_NOT_FOUND = "repo.resource.not.found";
任何?
答案 0 :(得分:0)
看起来像我在1点的Jasper Studio问题。 尝试检查主要报告中用于子报告的表达式。根据版本,Jasper Report Studio期望将子报告定义为
"folderOfyourSubReport/myreport_detail.jrxml"
或
"folderOfyourSubReport/myreport_detail.jasper"
答案 1 :(得分:0)
提供.jasper文件然后它工作。只运行一个报告而没有子报告我不需要提供它们:-)以为它们是在Spring Boot环境中即时生成的。