Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the JasperReportsMultiFormatView with ContentNegotiatingViewResolver?

I have html, json, and xml working fine with Spring's ContentNegotiatingViewResolver (Spring 3.2)

Trying to get csv output using a jasperreports.

Spring can find and parse the .jrxml file ok. Getting the following error when I try to view a .csv URL:

java.lang.ClassNotFoundException: org.springframework.ui.jasperreports.JasperReportsUtils
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)

Here's my webmvc-config.xml (is it correct?):

<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
        <property name="useNotAcceptableStatusCode" value="true"/>
        <property name="order" value="1"/>

        <property name="contentNegotiationManager">
            <bean class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
                <property name="favorPathExtension" value="true"/>
                <property name="ignoreAcceptHeader" value="false"/>
                <property name="mediaTypes">
                    <map>
                        <entry key="json" value="application/json"/>
                        <entry key="xml" value="application/xml"/>
                        <entry key="csv" value="text/csv"/>
                    </map>
                </property>
            </bean>
        </property>

        <property name="defaultViews">
            <list>
                <bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView">
                    <property name="objectMapper" ref="configuredObjectMapper"/>
                </bean>
                <bean class="org.springframework.web.servlet.view.xml.MarshallingView">
                    <property name="marshaller">
                        <bean class="org.springframework.oxm.xstream.XStreamMarshaller"/>
                    </property>
                </bean>
                <bean id="parties" class="org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView">
                    <property name="url" value="WEB-INF/parties.jrxml"/>
                    <property name="reportDataKey" value="dataSource"/>
                </bean>
            </list>
        </property>

        <property name="viewResolvers">
            <list>
                <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                    <property name="order" value="2"/>
                    <property name="prefix" value="/WEB-INF/views/"/>
                    <property name="suffix" value=".jsp"/>
                </bean>
            </list>
        </property>
    </bean>
like image 510
Neil McGuigan Avatar asked Feb 15 '23 22:02

Neil McGuigan


1 Answers

You need the spring-context-support jar in your classpath. Use maven:

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>${spring.version}</version>
    </dependency>
like image 143
Neil McGuigan Avatar answered Apr 25 '23 15:04

Neil McGuigan