4

我的 html、json 和 xml 与 Spring 的 ContentNegotiatingViewResolver (Spring 3.2) 配合得很好

尝试使用 jasperreports 获取 csv 输出。

Spring可以找到并解析.jrxml文件ok。当我尝试查看 .csv URL 时出现以下错误:

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

这是我的 webmvc-config.xml (正确吗?):

<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>
4

1 回答 1

8

您需要类路径中的 spring-context-support jar。使用行家:

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>${spring.version}</version>
    </dependency>
于 2014-03-13T22:09:23.687 回答