我正在尝试将旧的Grails应用程序迁移到grails 3.我使用的是grails 3.0.10。我在我的旧应用程序中使用渲染插件来生成PDF并且以这种方式构建了一堆PDF,我希望保持原样,所以我试图在我的grails 3应用程序中安装此渲染插件。正如所建议的那样,我在依赖项下的build.gradle中添加了以下行:
compile "org.grails.plugins:rendering:2.0.0-SNAPSHOT"
这似乎正确地拉动了这个插件.jar文件和run-app的工作原理。但是,当我尝试通过我的控制器将gsp呈现为PDF时,我得到了渲染插件中某些代码抛出的NullPointerException。
这是我从控制器方法生成PDF的代码:
renderPdf(template: "/pdfs/test", model: [name : 'Amarish'], filename: 'Hello-There.pdf')
由于上述方法不起作用,我还通过依赖注入将pdfRenderingService包含在控制器中,以不同的方式单独尝试,然后尝试以下方法:
ByteArrayOutputStream bytes = pdfRenderingService.render(template: "/pdfs/test", model: [name: 'Amarish'])
response.setContentLength(bytes.length)
response.setContentType('application/pdf')
response.outputStream.write(bytes)
我在下面包含堆栈跟踪。能告诉我如何解决这个问题吗?
ERROR org.grails.web.errors.GrailsExceptionResolver - NullPointerException occurred when processing request: [GET] /test/testPDF
Stacktrace follows:
java.lang.reflect.InvocationTargetException: null
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) ~[na:1.7.0_79]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) ~[na:1.7.0_79]
at java.lang.Thread.run(Thread.java:745) [na:1.7.0_79]
Caused by: java.lang.NullPointerException: null
at java.beans.Introspector.getPublicDeclaredMethods(Introspector.java:1281) ~[na:1.7.0_79]
at java.beans.Introspector.getTargetMethodInfo(Introspector.java:1141) ~[na:1.7.0_79]
at java.beans.Introspector.getBeanInfo(Introspector.java:416) ~[na:1.7.0_79]
at java.beans.Introspector.getBeanInfo(Introspector.java:163) ~[na:1.7.0_79]
at grails.plugins.rendering.document.RenderEnvironment.init(RenderEnvironment.groovy:31) ~[rendering-2.0.0-SNAPSHOT.jar:na]
at grails.plugins.rendering.document.RenderEnvironment.with(RenderEnvironment.groovy:68) ~[rendering-2.0.0-SNAPSHOT.jar:na]
at grails.plugins.rendering.document.RenderEnvironment.with(RenderEnvironment.groovy:60) ~[rendering-2.0.0-SNAPSHOT.jar:na]
at grails.plugins.rendering.document.XhtmlDocumentService.generateXhtml(XhtmlDocumentService.groovy:65) ~[rendering-2.0.0-SNAPSHOT.jar:na]
at grails.plugins.rendering.document.XhtmlDocumentService.createDocument(XhtmlDocumentService.groovy:35) ~[rendering-2.0.0-SNAPSHOT.jar:na]
at grails.plugins.rendering.RenderingService.render(RenderingService.groovy:36) ~[rendering-2.0.0-SNAPSHOT.jar:na]
at grails.plugins.rendering.RenderingService.render(RenderingService.groovy:35) ~[rendering-2.0.0-SNAPSHOT.jar:na]
at grails.plugins.rendering.RenderingService.render(RenderingService.groovy:65) ~[rendering-2.0.0-SNAPSHOT.jar:na]
at grails.plugins.rendering.RenderingTrait$Trait$Helper.renderPdf(RenderingTrait.groovy:47) ~[rendering-2.0.0-SNAPSHOT.jar:na]
at com.svp.controller.TestController$_closure1.doCall(TestController.groovy:14) ~[main/:na]
... 3 common frames omitted
答案 0 :(得分:4)
您的build.gradle依赖项需要的是
runtime "org.springframework:spring-test:4.2.1.RELEASE"
你的代码就可以了。祝你好运!
您还可以从here
添加最新版本