2012-03-24 55 views
0

我正在使用Grails 2.0.0。幾天前我開始使用Webflow插件,但今天遇到了一些麻煩。當我運行應用程序並擊中使用webflow的控制器時,我得到一個NullPointerException。如果我重新加載,我也會得到同樣的結果。如果我向控制器源文件添加一個空格(或者任何更改,只需強制重新編譯)並使用run-app保存,Grails會重新編譯控制器,並且後續請求可以正常工作。不幸的是,我不知道錯誤何時第一次出現。我一直無法將錯誤追溯到我做出的特定更改。Grails NPE對控制器的所有請求,直到重新編譯而不更改爲代碼

我該如何深入挖掘?爲什麼在運行時重新編譯控制器會修復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.SessionFactoryI[email protected]] 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 [[email protected]] 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 

從目標/ 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 [[email protected]] 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) 

回答

0

似乎已經通過使用grails create-controller創建了一個不同名稱的新控制器來解決,而c將代碼從舊控制器中選擇到新控制器。無法找到異常的根本原因。順便說一句,'grails clean'沒有解決它。

相關問題