我在 EJB3 和 Spring 3.0.6 Web 应用程序中使用 Apache FOP 1.1。编码:
FopFactory fopFactory = FopFactory.newInstance();
驻留在我的班级中(从 Spring MVC 转换器中调用)。如果此代码在方法之外(类级别),我会得到java.lang.ClassNotFoundException异常,而java.lang.ClassCircularityError异常是这条线在方法内。
请看下面的课程:
@Component
public class PdfReport extends BaseReportImpl implements IPdfReport{
@Override
public void createReport(OutputStream out, ResponseData responseData) throws IOException {
try {
//Construct a FopFactory
FopFactory fopFactory = FopFactory.newInstance();
//Construct fop with desired output format
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
//Setup JAXP using identity transformer
TransformerFactory factory = TransformerFactory.newInstance();
//identity transformer
Transformer transformer = factory.newTransformer();
//Setup input stream
Source src = new StreamSource(new File("/resources/detailsReport.fo"));
//Resulting SAX events (the generated FO) must be piped through to FOP
Result res = new SAXResult(fop.getDefaultHandler());
//Start XSLT transformation and FOP processing
transformer.transform(src, res);
} catch (FOPException e) {
throw new RuntimeException("Failed creating PDF report: " + e.getMessage(), e);
} catch (TransformerConfigurationException e) {
throw new RuntimeException("Failed setting up transformer for PDF report: " + e.getMessage(), e);
} catch (TransformerException e) {
throw new RuntimeException("Failed transforming PDF report: " + e.getMessage(), e);
}
}
}
但在那条线上我得到了一个例外:
org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.ClassCircularityError: org/apache/fop/apps/FOPException
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:839)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:585)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at utils.spring.UnloadFilterBean.doFilterInternal(UnloadFilterBean.java:58)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:207)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:176)
Caused by: java.lang.ClassCircularityError: org/apache/fop/apps/FOPException
at proj.report.PdfReport.createReport(PdfReport.java:37)
at protocol.ResponseDataConverter.writeInternal(ResponseDataConverter.java:94)
at protocol.ResponseDataConverter.writeInternal(ResponseDataConverter.java:1)
at org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:181)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.writeWithMessageConverters(AnnotationMethodHandlerAdapter.java:996)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.handleResponseBody(AnnotationMethodHandlerAdapter.java:954)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.getModelAndView(AnnotationMethodHandlerAdapter.java:903)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:438)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
... 26 more
请帮忙!
另外:
如果我移到FopFactory fopFactory = FopFactory.newInstance();
createReport() 方法之外,我会得到异常:
java.lang.ClassNotFoundException: org.apache.fop.apps.FopFactory
at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:297)
at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:270)
at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:64)
at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:179)
at weblogic.utils.classloaders.ChangeAwareClassLoader.loadClass(ChangeAwareClassLoader.java:43)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
... 86 more