我正在尝试使用渲染插件将html文件渲染为pdf,我的控制器方法是
def download() {
response.contentType = 'application/pdf'
response.setHeader("Content-disposition", "attachment; filename=\"download.pdf\"")
def items = []
(101..105).each { number->
ByteArrayOutputStream bos = new ByteArrayOutputStream();
items << [number:number, bytes:bos.toByteArray()]
}
renderPdf (template:'download', model:[items:items])
}
我的_download.gsp文件是,
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<body>
<g:each in="${items}" var="item">
<div>This is the barcode for the number: ${item.number}</div>
<hr/>
</g:each>
</body>
</html>
我在BuildConfig.groovy文件中添加了以下依赖项
compile ":rendering:1.0.0"
我收到了以下堆栈跟踪,
| Error 2015-08-06 16:35:28,925 [http-bio-8080-exec-1] ERROR errors.GrailsExceptionResolver - NullPointerException occurred when processing request: [GET] /wheeloflife/test/download
Stacktrace follows:
Message: null
Line | Method
->> 1281 | getPublicDeclaredMethods in java.beans.Introspector
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1141 | getTargetMethodInfo in ''
| 416 | getBeanInfo . . . . . . in ''
| 163 | getBeanInfo in ''
| 31 | init . . . . . . . . . . in grails.plugin.rendering.document.RenderEnvironment
| 68 | with in ''
| 60 | with . . . . . . . . . . in ''
| 65 | generateXhtml in grails.plugin.rendering.document.XhtmlDocumentService
| 35 | createDocument . . . . . in ''
| 36 | render in grails.plugin.rendering.RenderingService
| 35 | render . . . . . . . . . in ''
| 65 | render in ''
| 59 | doCall . . . . . . . . . in RenderingGrailsPlugin$_closure3
| 18 | download in com.codeharmony.wheeloflife.TestController$$EPKZmnkm
| 198 | doFilter . . . . . . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 53 | doFilter . . . . . . . . in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
| 62 | doFilter in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
| 1145 | runWorker . . . . . . . in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run . . . . . . . . . . in java.lang.Thread
注意更新:相同的代码库适用于grails版本2.2.4,仅在grails版本2.5.0中出现问题
答案 0 :(得分:1)
不知道您是否仍在寻找答案,但添加了
runtime "org.springframework:spring-test:4.1.5.RELEASE"
作为项目的依赖项解决了这个问题。