大家好,我们计划将我们的项目从 Java 8 升级到 Java 11。因此项目的 Spring 版本将从 Spring 4x 更改为 Spring 5x
视图解析是在 Spring 4x 中完成的,如下所示
1)spring xml配置:
<bean class="org.springframework.web.servlet.view.XmlViewResolver">
<property name="location" value="/WEB-INF/jasper-view.xml"/>
<property name="order" value="0"/>
</bean>
2) 碧玉-view.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!--here all the url value should contains the valid path for the jrxml file-->
<bean id="purchasePdf"
class="org.springframework.web.servlet.view.jasperreports.JasperReportsPdfView"
p:url="classpath:reports/purchaseReport.jrxml"
p:reportDataKey="datasource" />
所以随着升级 Spring 版本更新到 5.2.5.RELEASE 和 jasper 版本更新如下:
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.4.0</version>
</dependency>
该项目正在构建且没有错误,但在 Tomcat 服务器中部署时出现以下错误:
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.web.servlet.view.jasperreports.JasperReportsPdfView] for bean with name 'purchasePdf' defined in ServletContext resource [/WEB-INF/jasper-view.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.web.servlet.view.jasperreports.JasperReportsPdfView
似乎 Spring 5 已经放弃了对 Jasper 的支持
https://github.com/spring-projects/spring-framework/issues/17884
有没有替代解决方案?