Grails NPE对控制器的所有请求,直到重新编译而不更改代码

时间:2012-03-24 01:51:32

标签: grails

我正在使用Grails 2.0.0。我几天前开始使用webflow插件,今天遇到了一些麻烦。当我运行应用程序并点击使用webflow的控制器时,我得到一个NullPointerException。如果我重装,我会得到同样的。如果我向控制器源文件添加一个空格(或任何更改,只需要强制重新编译)并保存run-app仍然继续,Grails重新编译控制器,后续请求可以正常工作。不幸的是我不知道错误何时出现。我无法将错误追溯到我所做的特定更改。

我怎样才能深入挖掘这个?为什么在运行时重新编译控制器会修复NPE?

以下是我可以用来重现问题的控制器代码:

class ServicesController { 
  def index() { 
    redirect(action: "request") 
  } 

  def requestFlow = { 
    selectAssessments { 
      on("next") { 
      }.to("productInfo") 
      on("cancel").to("finish") 
    } 
  }
} 

这是控制台日志:

| Error 2012-03-18 21:43:11,272 ["http-bio-8080"-exec-4] ERROR errors.GrailsExceptionResolver  - NullPointerException occurred when processing request: [GET] /project/services/request 
Stacktrace follows: 
Message: null 
   Line | Method 
->> 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   908 | run     in     '' 
^   680 | run . . in java.lang.Thread 
| Error 2012-03-18 21:43:13,261 ["http-bio-8080"-exec-4] ERROR servlet.GrailsDispatcherServlet  - HandlerInterceptor.afterCompletion threw exception 
Message: No value for key [org.hibernate.impl.SessionFactoryImpl@57c40e95] bound to thread ["http-bio-8080"-exec-4] 
   Line | Method 
->> 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   908 | run     in     '' 
^   680 | run . . in java.lang.Thread 
| Error 2012-03-18 21:43:14,199 ["http-bio-8080"-exec-5] ERROR errors.GrailsExceptionResolver  - NullPointerException occurred when processing request: [GET] /project/services/request - parameters: 
execution: e1s1 
Stacktrace follows: 
Message: null 
   Line | Method 
->> 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   908 | run     in     '' 
^   680 | run . . in java.lang.Thread 
| Error 2012-03-18 21:43:14,262 ["http-bio-8080"-exec-5] ERROR servlet.GrailsDispatcherServlet  - HandlerInterceptor.afterCompletion threw exception 
Message: No value for key [org.hibernate.impl.SessionFactoryImpl@57c40e95] bound to thread ["http-bio-8080"-exec-5] 
   Line | Method 
->> 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   908 | run     in     '' 
^   680 | run . . in java.lang.Thread 

来自target / stacktrace.log:

2012-03-23 22:00:33,470 ["http-bio-8080"-exec-3] ERROR StackTrace  - Full Stack Trace:
java.lang.NullPointerException
    at org.codehaus.groovy.grails.orm.hibernate.support.GrailsOpenSessionInViewInterceptor.postHandle(GrailsOpenSessionInViewInterceptor.java:75)
    at org.springframework.web.servlet.handler.WebRequestHandlerInterceptorAdapter.postHandle(WebRequestHandlerInterceptorAdapter.java:61)
    at org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet.doDispatch(GrailsDispatcherServlet.java:342)
...  
2012-03-23 22:00:33,490 ["http-bio-8080"-exec-3] ERROR StackTrace  - Full Stack Trace:
java.lang.NullPointerException
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:680)
...
2012-03-23 22:00:36,725 ["http-bio-8080"-exec-3] ERROR StackTrace  - Full Stack Trace:
java.lang.IllegalStateException: No value for key [org.hibernate.impl.SessionFactoryImpl@12653c7e] bound to thread ["http-bio-8080"-exec-3]
    at org.springframework.transaction.support.TransactionSynchronizationManager.unbindResource(TransactionSynchronizationManager.java:209)
    at org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor.afterCompletion(OpenSessionInViewInterceptor.java:211)

1 个答案:

答案 0 :(得分:0)

似乎已经通过使用grails create-controller创建一个不同名称的新控制器,并将代码从旧控制器复制到新控制器来修复。无法找到异常的根本原因。顺便说一下,'grails clean'没有解决它。