Hibernate 绑定到线程的键没有值(Grails)
我正在用Grails开发一个web应用程序。我的环境规格是:Hibernate 绑定到线程的键没有值(Grails),hibernate,grails,service,Hibernate,Grails,Service,我正在用Grails开发一个web应用程序。我的环境规格是: Groovy Grails工具套件(GGTS)3.6.0.M1-e4.4-win32-x86_64 休眠4.3.5.3 Groovy 2.3 Grails2.4.0 Windows 8.1专业版 我启动应用程序,并在grails开始页面上选择以下控制器: class UploadController { def index() { } def upload() { forward(controller:
- Groovy Grails工具套件(GGTS)3.6.0.M1-e4.4-win32-x86_64
- 休眠4.3.5.3
- Groovy 2.3
- Grails2.4.0
- Windows 8.1专业版
class UploadController {
def index() { }
def upload() {
forward(controller: "parser", action: "takeUploadedFiles")
}
}
import org.springframework.web.multipart.commons.CommonsMultipartFile
class ParserController {
def multipartToFileService
def parserService
def index() { }
def takeUploadedFiles() {
List fileList = request.getFiles('files') // 'files' is the name of the input
fileList.each { file -> multipartToFileService.convert(file) }
redirect(action: "parse")
}
def parse() {
parserService.parse()
}
}
只有这个控制器就不会发生任何事情。相应的.gsp就是这个上传表单。我用它一次上传多个文件
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<meta name="layout" content="main"/>
<title>Inhalte einlesen</title>
</head>
<body>
<div class="body">
<g:uploadForm controller="upload" action="upload" autocomplete="off">
<label for="files">Bitte alle HTML-Dateien einer Kategorie auswählen:</label>
<input type="file" id="files" name="files" multiple="multiple" />
<input type="hidden" id="MAX_FILE_SIZE" name="MAX_FILE_SIZE" value="30000" />
<g:submitButton name="add" class="save button medium" value="Hochladen" />
</g:uploadForm>
</div>
</body>
</html>
所以我上传了一个.html。
在这一点上,我得到了一个例外:
2014-06-02 23:04:33,127 [tomcat-http--9] ERROR servlet.GrailsDispatcherServlet - HandlerInterceptor.afterCompletion threw exception
java.lang.IllegalStateException: No value for key [org.hibernate.internal.SessionFactoryImpl@6398813a] bound to thread [tomcat-http--9]
at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:198)
at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
此异常不会停止应用程序,即使解析已完美完成。
但我不理解这个例外,我发现这可能有点关系
使用我在PaserController中注入的事务服务。
在没有服务注入的情况下,我不会得到异常(当然,我会得到一个MissingPropertyException):
有什么办法可以避免这个非法的州例外吗?这似乎就是问题所在:
- ID:GRAILS-11481
- 描述:GrailsDispatcherServlet在使用forward()和render()时引发IllegalStateException
import org.springframework.web.multipart.commons.CommonsMultipartFile
class ParserController {
// def multipartToFileService
// def parserService
def index() { }
def takeUploadedFiles() {
List fileList = request.getFiles('files') // 'files' is the name of the input
fileList.each { file -> multipartToFileService.convert(file) }
redirect(action: "parse")
}
def parse() {
parserService.parse()
}
}