如何将jasper整合到jhipster项目中

时间:2017-12-21 15:29:39

标签: java spring-boot jasper-reports jhipster

我试图将jasper报告集成到jhipster proyect,jhipster 4.11,mysql。 我需要从angular调用report,并以pdf,xls和csv显示此报告。

我已创建此控制器

package org.seguritech.cp.web.controller;

import net.bytebuddy.asm.Advice;
import org.seguritech.cp.service.ConsultaPlacaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView;
import org.springframework.web.servlet.view.jasperreports.JasperReportsPdfView;

import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;

@Controller
public class ReportController {

    @Autowired
    private DataSource dataSource;

    @Autowired
    private ConsultaPlacaService consultaPlacaService;

    @RequestMapping(path = "/pdf", method = RequestMethod.GET)
    public ModelAndView report() {

        JasperReportsMultiFormatView view = new JasperReportsMultiFormatView();
        view.setUrl("classpath:Consultas.jrxml");
        //view.setJdbcDataSource(dataSource);

        Map<String, Object> params = new HashMap<>();
        params.put("datasource", consultaPlacaService.findAll());

        return new ModelAndView(view, params);
    }
}

报告Consultas.jrxml位于资源折叠

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.5.0.final using JasperReports Library version 6.5.0  -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Coffee_Landscape" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="df013db5-f76e-44d3-b0df-bcbc46d93160">
    <property name="com.jaspersoft.studio.data.sql.tables">
        <![CDATA[YENvbnN1bHRhUGxhY2FzYC5jb3Jwb3JhY2lvbiBBUyAsMjQ5LDIxOSw5ZWVkNGZmOC00YjBkLTQ3
OGItODVjNi01OTBkOGI4YzdlNDc7YENvbnN1bHRhUGxhY2FzYC5tdW5pY2lwaW8gQVMgLDIzMCwx
NTMsZmRjZGQ3NTctNDk1ZS00NWEyLTljYTEtMDIxMWI4NWQyYTJkO2BDb25zdWx0YVBsYWNhc2Au
Y29uc3VsdGFfcGxhY2EgLDE1LDE1LDRmNzZkNDFlLTM0MGEtNGVlNy04YTNiLWI0MzAwYjY0ZjAy
ODs=]]>
    </property>
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="New Data Adapter (2)"/>
    <style name="Title" fontName="Times New Roman" fontSize="50" isBold="true"/>
    <style name="SubTitle" forecolor="#736343" fontName="Arial" fontSize="18"/>
    <style name="Column header" forecolor="#666666" fontName="Arial" fontSize="12" isBold="true"/>
    <style name="Detail" fontName="Arial" fontSize="12"/>
    <style name="Row" mode="Transparent">
        <conditionalStyle>
            <conditionExpression><![CDATA[$V{REPORT_COUNT}%2 == 0]]></conditionExpression>
            <style backcolor="#E6DAC3"/>
        </conditionalStyle>
    </style>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="issi" class="java.lang.String">
        <property name="com.jaspersoft.studio.field.label" value="issi"/>
        <property name="com.jaspersoft.studio.field.tree.path" value="consulta_placa"/>
    </field>
    <field name="responsable" class="java.lang.String">
        <property name="com.jaspersoft.studio.field.label" value="responsable"/>
        <property name="com.jaspersoft.studio.field.tree.path" value="consulta_placa"/>
    </field>
    <field name="municipio" class="java.lang.String">
        <property name="com.jaspersoft.studio.field.label" value="municipio"/>
        <property name="com.jaspersoft.studio.field.tree.path" value="municipio"/>
    </field>
    <field name="corporacion" class="java.lang.String">
        <property name="com.jaspersoft.studio.field.label" value="corporacion"/>
        <property name="com.jaspersoft.studio.field.tree.path" value="corporacion"/>
    </field>
    <field name="fecha" class="java.sql.Date">
        <property name="com.jaspersoft.studio.field.label" value="fecha"/>
        <property name="com.jaspersoft.studio.field.tree.path" value="consulta_placa"/>
    </field>
    <field name="consulta" class="java.lang.String">
        <property name="com.jaspersoft.studio.field.label" value="consulta"/>
        <property name="com.jaspersoft.studio.field.tree.path" value="consulta_placa"/>
    </field>
    <field name="metodo" class="java.lang.String">
        <property name="com.jaspersoft.studio.field.label" value="metodo"/>
        <property name="com.jaspersoft.studio.field.tree.path" value="consulta_placa"/>
    </field>
    <field name="estado" class="java.lang.Boolean">
        <property name="com.jaspersoft.studio.field.label" value="estado"/>
        <property name="com.jaspersoft.studio.field.tree.path" value="consulta_placa"/>
    </field>
    <field name="resultado" class="java.lang.String">
        <property name="com.jaspersoft.studio.field.label" value="resultado"/>
        <property name="com.jaspersoft.studio.field.tree.path" value="consulta_placa"/>
    </field>
    <field name="coordenadas" class="java.lang.String">
        <property name="com.jaspersoft.studio.field.label" value="coordenadas"/>
        <property name="com.jaspersoft.studio.field.tree.path" value="consulta_placa"/>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="136" splitType="Stretch">
            <image>
                <reportElement x="0" y="0" width="164" height="126" uuid="1c003177-754c-448f-8ce1-16868856f545"/>
                <imageExpression><![CDATA["coffee.jpg"]]></imageExpression>
            </image>
            <staticText>
                <reportElement style="Title" x="270" y="0" width="263" height="62" uuid="bc1ce1da-8232-46ea-be55-cec4abb986dd"/>
                <textElement verticalAlignment="Middle"/>
                <text><![CDATA[Coffee Title]]></text>
            </staticText>
            <staticText>
                <reportElement style="SubTitle" x="303" y="62" width="196" height="22" uuid="f6a78448-8260-4445-a9e0-e3fb53b080d9"/>
                <textElement>
                    <font fontName="Times New Roman"/>
                </textElement>
                <text><![CDATA[Coffee SubTitle]]></text>
            </staticText>
            <staticText>
                <reportElement x="172" y="94" width="383" height="42" uuid="8240065e-64b6-4170-b5d9-6341598e7b35"/>
                <textElement textAlignment="Right">
                    <font size="10"/>
                </textElement>
                <text><![CDATA[Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce auctor purus gravida arcu aliquam mattis. Donec et nulla libero, ut varius massa. Nulla sed turpis elit. Etiam aliquet mauris a ligula hendrerit in auctor leo lobortis.]]></text>
            </staticText>
            <image>
                <reportElement x="633" y="-73" width="219" height="209" uuid="4aa6f4d1-27dc-4b34-9227-59e19ce2c959"/>
                <imageExpression><![CDATA["coffee_stain.png"]]></imageExpression>
            </image>
        </band>
    </title>
    <pageHeader>
        <band splitType="Stretch"/>
    </pageHeader>
    <columnHeader>
        <band height="16" splitType="Stretch">
            <line>
                <reportElement positionType="FixRelativeToBottom" x="0" y="15" width="802" height="1" uuid="e9d2002a-c8ee-4649-a258-640dad29110c"/>
                <graphicElement>
                    <pen lineWidth="0.5" lineColor="#999999"/>
                </graphicElement>
            </line>
            <staticText>
                <reportElement style="Column header" x="0" y="0" width="80" height="15" forecolor="#736343" uuid="b483fb52-d297-4ad2-a666-7ff8397b4498">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="1ad24f79-738d-458c-a8dd-a8632476a94c"/>
                </reportElement>
                <text><![CDATA[issi]]></text>
            </staticText>
            <staticText>
                <reportElement style="Column header" x="80" y="0" width="80" height="15" forecolor="#736343" uuid="f2213c2a-8b6d-4200-ac48-80b460f6b7ce">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="87e84b26-e9e5-4fa9-8c11-b5c8a7547733"/>
                </reportElement>
                <text><![CDATA[responsable]]></text>
            </staticText>
            <staticText>
                <reportElement style="Column header" x="160" y="0" width="80" height="15" forecolor="#736343" uuid="94d65a5a-bd9d-4963-a5b2-14fb1bc386ca">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="eee60cc9-c6ce-4954-bdf1-a99fad4c37c4"/>
                </reportElement>
                <text><![CDATA[municipio]]></text>
            </staticText>
            <staticText>
                <reportElement style="Column header" x="240" y="0" width="80" height="15" forecolor="#736343" uuid="064aff57-e44c-484d-8a7a-d080827d4df0">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="a8534a72-7d2d-442c-bca8-a1be84ea7c98"/>
                </reportElement>
                <text><![CDATA[corporacion]]></text>
            </staticText>
            <staticText>
                <reportElement style="Column header" x="320" y="0" width="80" height="15" forecolor="#736343" uuid="9a28366e-c502-49f4-a4ae-a38b54482edf">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="af83d51b-b462-4cd9-be4f-655707a431b2"/>
                </reportElement>
                <text><![CDATA[fecha]]></text>
            </staticText>
            <staticText>
                <reportElement style="Column header" x="400" y="0" width="80" height="15" forecolor="#736343" uuid="2df3aaa4-7325-4f36-9df8-d83fc8ef3862">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="790dbc78-02e3-494e-8129-01c1cafc31fd"/>
                </reportElement>
                <text><![CDATA[consulta]]></text>
            </staticText>
            <staticText>
                <reportElement style="Column header" x="480" y="0" width="80" height="15" forecolor="#736343" uuid="e31b2973-1b6b-4337-8dfc-ade0e0fde046">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="caf7673e-361d-46a9-a67e-223c401e9af3"/>
                </reportElement>
                <text><![CDATA[metodo]]></text>
            </staticText>
            <staticText>
                <reportElement style="Column header" x="560" y="0" width="80" height="15" forecolor="#736343" uuid="cd19d3dc-cf4f-4c28-9700-a7c251c5a009">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="70c3384c-5238-4d9c-a01d-7f423d68c706"/>
                </reportElement>
                <text><![CDATA[estado]]></text>
            </staticText>
            <staticText>
                <reportElement style="Column header" x="640" y="0" width="80" height="15" forecolor="#736343" uuid="cc71ac98-2fac-4268-bd2c-9ec0f7879405">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="38786f27-fcda-4173-b256-baac3354ca3a"/>
                </reportElement>
                <text><![CDATA[resultado]]></text>
            </staticText>
            <staticText>
                <reportElement style="Column header" x="720" y="0" width="80" height="15" forecolor="#736343" uuid="cc5e28f9-80b1-4ff1-9840-a32dc3dacc46">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="649685c6-f235-4e9f-a05b-72fd94020aa9"/>
                </reportElement>
                <text><![CDATA[coordenadas]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="15" splitType="Stretch">
            <frame>
                <reportElement style="Row" mode="Opaque" x="0" y="0" width="802" height="15" uuid="fa7cec56-4ec1-48e6-a26e-7266a995d174"/>
                <textField isStretchWithOverflow="true">
                    <reportElement style="Detail" x="0" y="0" width="80" height="15" uuid="e36b1316-7025-4a62-884e-e5abf532890f">
                        <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="1ad24f79-738d-458c-a8dd-a8632476a94c"/>
                    </reportElement>
                    <textFieldExpression><![CDATA[$F{issi}]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true">
                    <reportElement style="Detail" x="80" y="0" width="80" height="15" uuid="a998d292-a88c-4c61-ad8b-98e8e93a9bd8">
                        <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="87e84b26-e9e5-4fa9-8c11-b5c8a7547733"/>
                    </reportElement>
                    <textFieldExpression><![CDATA[$F{responsable}]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true">
                    <reportElement style="Detail" x="160" y="0" width="80" height="15" uuid="afc29e65-01ed-45e5-a281-cb05010f03ea">
                        <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="eee60cc9-c6ce-4954-bdf1-a99fad4c37c4"/>
                    </reportElement>
                    <textFieldExpression><![CDATA[$F{municipio}]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true">
                    <reportElement style="Detail" x="240" y="0" width="80" height="15" uuid="ab93e51a-940f-45e8-b812-bd1e2b895cbe">
                        <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="a8534a72-7d2d-442c-bca8-a1be84ea7c98"/>
                    </reportElement>
                    <textFieldExpression><![CDATA[$F{corporacion}]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true">
                    <reportElement style="Detail" x="320" y="0" width="80" height="15" uuid="a46008a5-0b23-43b2-82be-65cca02f9d62">
                        <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="af83d51b-b462-4cd9-be4f-655707a431b2"/>
                    </reportElement>
                    <textFieldExpression><![CDATA[$F{fecha}]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true">
                    <reportElement style="Detail" x="400" y="0" width="80" height="15" uuid="39f65bb4-b241-4317-aaae-28313712f683">
                        <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="790dbc78-02e3-494e-8129-01c1cafc31fd"/>
                    </reportElement>
                    <textFieldExpression><![CDATA[$F{consulta}]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true">
                    <reportElement style="Detail" x="480" y="0" width="80" height="15" uuid="43e57583-6de8-4e18-8552-f554c58a29cc">
                        <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="caf7673e-361d-46a9-a67e-223c401e9af3"/>
                    </reportElement>
                    <textFieldExpression><![CDATA[$F{metodo}]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true">
                    <reportElement style="Detail" x="560" y="0" width="80" height="15" uuid="ac2aea71-e862-425d-a7bb-cb146559a591">
                        <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="70c3384c-5238-4d9c-a01d-7f423d68c706"/>
                    </reportElement>
                    <textFieldExpression><![CDATA[$F{estado}]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true">
                    <reportElement style="Detail" x="640" y="0" width="80" height="15" uuid="8eec39e6-35f3-4055-b246-316d59c85252">
                        <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="38786f27-fcda-4173-b256-baac3354ca3a"/>
                    </reportElement>
                    <textFieldExpression><![CDATA[$F{resultado}]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true">
                    <reportElement style="Detail" x="720" y="0" width="80" height="15" uuid="d7e67806-09d3-48ed-84f3-0a99635e0a84">
                        <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="649685c6-f235-4e9f-a05b-72fd94020aa9"/>
                    </reportElement>
                    <textFieldExpression><![CDATA[$F{coordenadas}]]></textFieldExpression>
                </textField>
            </frame>
        </band>
    </detail>
    <columnFooter>
        <band height="6" splitType="Stretch">
            <line>
                <reportElement positionType="FixRelativeToBottom" x="0" y="3" width="802" height="1" uuid="fa5e88d5-a011-4e32-8f12-ce923f903111"/>
                <graphicElement>
                    <pen lineWidth="0.5" lineColor="#999999"/>
                </graphicElement>
            </line>
        </band>
    </columnFooter>
    <pageFooter>
        <band height="25" splitType="Stretch">
            <frame>
                <reportElement mode="Opaque" x="-21" y="1" width="843" height="24" forecolor="#D0B48E" backcolor="#F2EBDF" uuid="5d8169bd-4a75-48c8-8a68-6d3ad5ba9402"/>
                <textField evaluationTime="Report">
                    <reportElement style="Column header" x="783" y="1" width="40" height="20" forecolor="#736343" uuid="e5e27efa-b599-499b-9ca3-848cb511cb7b"/>
                    <textElement verticalAlignment="Middle">
                        <font size="10" isBold="false"/>
                    </textElement>
                    <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement style="Column header" x="703" y="1" width="80" height="20" forecolor="#736343" uuid="18cfe1ca-f7d6-48b0-9827-28578b42a5e0"/>
                    <textElement textAlignment="Right" verticalAlignment="Middle">
                        <font size="10" isBold="false"/>
                    </textElement>
                    <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
                </textField>
                <textField pattern="EEEEE dd MMMMM yyyy">
                    <reportElement style="Column header" x="22" y="1" width="197" height="20" forecolor="#736343" uuid="fbce24bb-3cb1-44a3-8eec-8c067ddbe5b5"/>
                    <textElement verticalAlignment="Middle">
                        <font size="10" isBold="false"/>
                    </textElement>
                    <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
                </textField>
            </frame>
        </band>
    </pageFooter>
    <summary>
        <band splitType="Stretch"/>
    </summary>
</jasperReport>

当我运行te app并运行端点时,我有这个错误:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: ApplicationObjectSupport instance [org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView: unnamed; URL [classpath:Consultas.jrxml]] does not run in an ApplicationContext
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
    at com.codahale.metrics.servlet.AbstractInstrumentedFilter.doFilter(AbstractInstrumentedFilter.java:111)
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:110)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.seguritech.cp.security.jwt.JWTFilter.doFilter(JWTFilter.java:36)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:96)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:108)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
    at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:64)
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
    at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
    at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
    at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:332)
    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:812)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: ApplicationObjectSupport instance [org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView: unnamed; URL [classpath:Consultas.jrxml]] does not run in an ApplicationContext
    at org.springframework.context.support.ApplicationObjectSupport.getApplicationContext(ApplicationObjectSupport.java:141)
    at org.springframework.web.context.support.WebApplicationObjectSupport.getWebApplicationContext(WebApplicationObjectSupport.java:107)
    at org.springframework.web.context.support.WebApplicationObjectSupport.getServletContext(WebApplicationObjectSupport.java:128)
    at oorg.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1286)
    at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1041)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:984)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    ... 99 common frames omitted

你能帮助我吗?

1 个答案:

答案 0 :(得分:2)

您好我在SpringConlay的ApplicationContext中修复此错误

@Autowired
    private ApplicationContext context;

    @Autowired
    private ConsultaPlacaService consultaPlacaService;

@RequestMapping(path = "/pdf", method = RequestMethod.GET)
    public ModelAndView report() {

        JasperReportsPdfView view = new JasperReportsPdfView();
        view.setUrl("classpath:reporte_consulta_placas.jrxml");
        view.setApplicationContext(context);

        Map<String, Object> params = new HashMap<>();
        params.put("datasource", consultaPlacaService.findAll());

        return new ModelAndView(view, params);
    }

工作好。

How to get bean using application context in spring boot