1

我正在做一个控制器以在用户需要时显示JR报告。我正在使用Maven + Eclipse + JasperReports API

该项目编译得很好,但是当我尝试访问我的控制器以获取报告时,我看到了这个异常:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'reciboPago': Initialization of bean failed; nested exception is org.springframework.context.ApplicationContextException: Could not parse JasperReports report from ServletContext resource [/WEB-INF/classes/config/reports/IntegracionCGC.jasper]; nested exception is net.sf.jasperreports.engine.JRException: Error loading object from InputStream
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
.
.
.
.
net.sf.jasperreports.engine.JRException: Error loading object from InputStream
    net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:215)
    org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView.loadReport(AbstractJasperReportsView.java:496)
    org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView.loadReport(AbstractJasperReportsView.java:476)
    org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView.initApplicationContext(AbstractJasperReportsView.java:306)
    org.springframework.context.support.ApplicationObjectSupport.initApplicationContext(ApplicationObjectSupport.java:119)
    org.springframework.web.context.support.WebApplicationObjectSupport.initApplicationContext(WebApplicationObjectSupport.java:72)
    org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:73)
    org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:117)
    org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:92)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:394)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1448)
.
.
.
causa raíz

java.io.StreamCorruptedException: invalid stream header: EFBFBDEF
    java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:782)
    java.io.ObjectInputStream.<init>(ObjectInputStream.java:279)
    net.sf.jasperreports.engine.util.ContextClassLoaderObjectInputStream.<init>(ContextClassLoaderObjectInputStream.java:53)
    net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:210)
    org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView.loadReport(AbstractJasperReportsView.java:496)
    org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView.loadReport(AbstractJasperReportsView.java:476)
    org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView.initApplicationContext(AbstractJasperReportsView.java:306)
    org.springframework.context.support.ApplicationObjectSupport.initApplicationContext(ApplicationObjectSupport.java:119)
    org.springframework.web.context.support.WebApplicationObjectSupport.initApplicationContext(WebApplicationObjectSupport.java:72)
    org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:73)
    org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:117)

这是我的控制器:

@Controller
@RequestMapping("/pago")
public class JasperReportsController {

  public static final Log logger = LogFactory.getLog(JasperReportsController.class);

  @RequestMapping(value = "/recibo", method = RequestMethod.GET)
  public String generarReciboPago(ModelMap modelMap, HttpServletResponse response) {
    List<ReciboPagoJasperDTO> lista = new ArrayList<ReciboPagoJasperDTO>(1);
    ReciboPagoJasperDTO dto = new ReciboPagoJasperDTO();
    dto.setMonto("6789.0");
    dto.setNombre("Pedro Romero");
    lista.add(dto);
    // response.setHeader("Content-type", "application/pdf");
    // response.setHeader("Content-Disposition","attachment; filename=\"recibo.pdf\"");
    JRBeanCollectionDataSource jrbean = new JRBeanCollectionDataSource(lista, false);
    modelMap.put("reciboKey", jrbean);
    return ("reciboPago");
  }

  @RequestMapping(method = RequestMethod.GET, value = "docx")
  public ModelAndView generateDocxReport(ModelAndView modelAndView) {
    logger.debug("--Generating docx report--");
    Map<String, Object> parameterMap = new HashMap<String,Object>();

    List<ReciboPagoJasperDTO> lista = new ArrayList<ReciboPagoJasperDTO>(1);
    ReciboPagoJasperDTO dto = new ReciboPagoJasperDTO();
    dto.setMonto("6789.0");
    dto.setNombre("Pedro Romero");
    lista.add(dto);

    JRDataSource JRdataSource = new JRBeanCollectionDataSource(lista);
    parameterMap.put("datasource", JRdataSource);

    modelAndView = new ModelAndView("docxReport", parameterMap);
    return modelAndView;
  }
}

有什么建议吗?

4

1 回答 1

2

最后我得到了解决方案。我将此添加到我的 POM 中。我希望这对其他人有用。

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.6</version>
    <configuration>

      <nonFilteredFileExtensions>
        <nonFilteredFileExtension>jasper</nonFilteredFileExtension>
      </nonFilteredFileExtensions>

    </configuration>
  </plugin>

问候!

于 2012-09-28T18:32:14.270 回答