我开发了一个完全在localhost上运行的grails 2.3.5应用程序,但在部署到我的Tomcat 7服务器时,出现以下错误:
Error 500: Internal Server Error
URI
/schedulingAPI-0.1/tests
Class
org.codehaus.groovy.runtime.typehandling.GroovyCastException
Message
Cannot cast object 'org.hibernate.impl.SessionFactoryImpl@5ac08512' with class 'org.hibernate.impl.SessionFactoryImpl' to class 'org.codehaus.groovy.grails.orm.hibernate.SessionFactoryProxy'
跟踪:
Line | Method
->> 12 | $tt__parseXML in mp.ra.SchedulingService
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 21 | $tt__index in mp.ra.TestController
| 200 | doFilter . . . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 88 | processFilterChain in com.odobo.grails.plugin.springsecurity.rest.RestTokenValidationFilter
| 66 | doFilter in ''
| 53 | doFilter . . . . . in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
| 108 | doFilter in com.odobo.grails.plugin.springsecurity.rest.RestAuthenticationFilter
| 49 | doFilter . . . . . in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
| 82 | doFilter in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
| 66 | doFilter . . . . . in com.odobo.grails.plugin.springsecurity.rest.RestLogoutFilter
| 82 | doFilter in com.brandseye.cors.CorsFilter
| 1145 | runWorker . . . . in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run . . . . . . . in java.lang.Thread
我唯一的线索是这与springsecurity插件有关。
修改 这是我的mp.ra.SchedulingService中发生错误的代码fragemtn:
def parseXML() {
LessonParser par = new LessonParser(sessionFactory:sessionFactory)
//par.parse(["src/data/tweede/"])
par.parse(["src/data/access/","src/data/tweede/"])
}
这是我的LessonParser类:
package mp.data.parser
import javax.xml.parsers.SAXParser
import groovy.io.FileType
import javax.xml.parsers.SAXParserFactory
import mp.ra.*
import org.codehaus.groovy.grails.orm.hibernate.SessionFactoryProxy
import org.xml.sax.InputSource
class LessonParser {
SessionFactoryProxy sessionFactory
public void parse(baseFileLocations){
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
//alle directories overlopen
baseFileLocations.each(){ location ->
def dir = new File(location)
//alle bestanden van directory inlezen
dir.eachFile(){ file ->
if (file.name.endsWith(".xml")) {
// print file.name
//alle bestanden parsen
InputStream inputStream = new FileInputStream(file);
Reader reader = new InputStreamReader(inputStream, "UTF-8");
InputSource is = new InputSource(reader);
is.setEncoding("UTF-8")
LessonHandler handler = new LessonHandler(sessionFactory)
saxParser.parse(is, handler);
}
}
}
}
}
我使用SesionFactory的原因是为了减少读取XML文件的时间。如果不使用SessionFactory,这需要大约20分钟,而使用SessionFactory需要几分钟。