我使用Spring的ContentNegotiatingViewResolver(Spring 3.2)正常运行html,json和xml
尝试使用jasperreports获取csv输出。
Spring可以找到并解析.jrxml文件。尝试查看.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>
答案 0 :(得分:9)
您需要在类路径中使用spring-context-support jar。使用maven:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>