gpt4 book ai didi

java - 使用 Spring MVC 获取 JR 报告时出现异常

转载 作者:行者123 更新时间:2023-11-30 04:39:34 24 4
gpt4 key购买 nike

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

该项目编译良好,但是当我尝试访问我的 Controller 以获取报告时,我看到了此异常:

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 :

@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;
}
}

对此有什么建议吗?

最佳答案

终于找到解决办法了。我将其添加到我的 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>

您好!

关于java - 使用 Spring MVC 获取 JR 报告时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12631775/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com