【问题标题】:Could not load JasperReports report from class path resource. The html postfix was added to template's name无法从类路径资源加载 JasperReports 报告。 html 后缀被添加到模板的名称中
【发布时间】:2017-02-03 09:42:00
【问题描述】:

我在我的项目中使用springboot1.4 + jasperreports 6.2。我可以在启动tomcat服务器时下载rpt_monthreport_boxsales.jrxml,2~3天后会显示异常并重新启动tomcat服务器系统将正常。让我感到困惑的是“.html”是从哪里来的?

org.springframework.context.ApplicationContextException: 
Could not load JasperReports report from class path resource [jasperreports/rpt_monthreport_boxsales.html.jrxml]; 
nested exception is java.io.FileNotFoundException: 
class path resource [jasperreports/rpt_monthreport_boxsales.html.jrxml] cannot be opened because it does not exist

我的代码:

@Bean(name = "velocityViewResolver")
    public VelocityLayoutViewResolver velocityViewResolver(VelocityProperties properties) {
         VelocityLayoutViewResolver resolver = new VelocityLayoutViewResolver();
            properties.applyToViewResolver(resolver);
            resolver.setSuffix(".vm");
            resolver.setLayoutUrl("include/layout.vm"); 
            resolver.setOrder(1);
            return resolver;
    }

    @Bean
    public JasperReportsViewResolver getJasperReportsViewResolver() {
      JasperReportsViewResolver resolver = new JasperReportsViewResolver();
      resolver.setPrefix("classpath:/jasperreports/");
      resolver.setSuffix(".jrxml");
      resolver.setReportDataKey("datasource");
      resolver.setViewNames("rpt_*");
      resolver.setViewClass(JasperReportsMultiFormatView.class);
      resolver.setOrder(0);
      return resolver;
    } 

    @RequestMapping(value = "/exportMonthReportBoxSales")
public ModelAndView exportMonthReportBoxSales(ModelMap modelMap, ModelAndView modelAndView,@RequestParam(value = "month_str", required = true)String month_str) throws Exception {
    List<MonthReport> monthReport_list = g20spaReportService.queryMonthReportBoxSales(month_str);
    JRDataSource jrDataSource = new JRBeanCollectionDataSource(monthReport_list);
    modelMap.put("datasource", jrDataSource);
    modelMap.put("format","xls");
    modelAndView = new ModelAndView("rpt_monthreport_boxsales", modelMap);
    return modelAndView;
}

【问题讨论】:

  • It confused me that where ".html" comes from? - 看起来像代码的某些部分添加了这个后缀。你试过调试吗?
  • 感谢亚历克斯的回复。看起来像代码的某些部分添加了这个后缀。你试过调试吗? >>>> 这个 bug 不能在本地环境中重现。而且我没有在我的项目中添加“.html”。

标签: java spring jasper-reports filenotfoundexception


【解决方案1】:

我通过禁止默认的 html 后缀解决了这个问题。

 @Override
    public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
        configurer.favorPathExtension(false).
            favorParameter(false).
            ignoreAcceptHeader(false).
            useJaf(false).
            defaultContentType(MediaType.TEXT_HTML).
            mediaType("json", MediaType.APPLICATION_JSON);
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-27
    • 1970-01-01
    • 2011-04-22
    • 1970-01-01
    • 2010-10-26
    • 1970-01-01
    • 1970-01-01
    • 2020-09-02
    相关资源
    最近更新 更多