2013-07-15 51 views
5

我有與Spring的ContentNegotiatingViewResolver(Spring 3.2)工作正常的html,json和xml如何在ContentNegotiatingViewResolver中使用JasperReportsMultiFormatView?

嘗試使用jasperreports獲取csv輸出。

Spring可以找到並解析.jrxml文件。得到以下錯誤,當我嘗試查看一個.csv網址:

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> 

回答

8

您需要的彈簧上下文支持jar在你的classpath中。使用maven:

<dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context-support</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 
相關問題