ClassCastException:org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest无法强制转换GrailsWebRequest

时间:2014-07-13 11:57:23

标签: java spring tomcat grails tomcat7

当我在tomcat上部署2个相同的应用程序时,我遇到了问题。战争是一样的,只有应用名称是不同的。

Tomcat随机返回(仅适用于第二个加载的应用):

错误500

  

java.lang.ClassCastException:   org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest不能   施放到org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest

我的BuildConfig

grails.servlet.version = "3.0" // Change depending on target container compliance (2.5 or 3.0)
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.work.dir = "target/work"
grails.project.target.level = 1.6
grails.project.source.level = 1.6
grails.project.war.file = "target/${appName}.war"

forkConfig = [maxMemory: 1024, minMemory: 64, debug: false, maxPerm: 256]
grails.project.fork = [
   test: forkConfig, // configure settings for the test-app JVM
   run: forkConfig, // configure settings for the run-app JVM
   war: forkConfig, // configure settings for the run-war JVM
   console: forkConfig // configure settings for the Swing console JVM
]

grails.project.dependency.resolver = "maven" // or ivy
grails.project.dependency.resolution = {
    // inherit Grails' default dependencies
    inherits("global") {
        // specify dependency exclusions here; for example, uncomment this to disable ehcache:
        // excludes 'ehcache'
    }
    log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
    checksums true // Whether to verify checksums on resolve
    legacyResolve false // whether to do a secondary resolve on plugin installation, not advised and here for backwards compatibility

    repositories {
        inherits true // Whether to inherit repository definitions from plugins
        grailsPlugins()
        grailsHome()
        grailsCentral()
        mavenCentral()

        // uncomment these to enable remote dependency resolution from public Maven repositories
        mavenCentral()
        mavenRepo('file:///c:/mvn_repo')
        mavenRepo "http://snapshots.repository.codehaus.org"
        mavenRepo "http://repository.codehaus.org"
        mavenRepo "http://download.java.net/maven/2/"
        //mavenRepo "http://repository.jboss.com/maven2/"
    }
    dependencies {
        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.

        //runtime 'com.microsoft.sqlserver:sqljdbc4:4.0'
        runtime 'com.microsoft.windowsazure:microsoft-windowsazure-api:0.4.1'
        compile 'commons-collections:commons-collections:3.2.1'

        compile 'joda-time:joda-time:2.1'
        compile 'com.lowagie:itext:2.1.7'
        compile 'net.sf.jasperreports:jasperreports:5.5.0'

    }

    plugins {

        build ":tomcat:7.0.54"

        // plugins for the compile step
        compile ":scaffolding:2.0.3"
        compile ':cache:1.1.7'

        // plugins needed at runtime but not for compilation
        runtime ':hibernate:3.6.10.10' // or ":hibernate4:4.1.11.BUILD-SNAPSHOT"
        runtime ":database-migration:1.3.3"

        runtime ':resources:1.2.7'

        // Uncomment these (or add new ones) to enable additional resources capabilities
        runtime ":zipped-resources:1.0.1"
        runtime ":cached-resources:1.1"
        //runtime ":yui-minify-resources:0.1.5"

        compile ':spring-security-core:1.2.7.3'
        compile ":cache-headers:1.1.7"
        compile ':jasper:1.6.1'

        compile ':mail:1.0.6'
        compile ":profiler:0.5"
        compile ':smart-sprites-resources:0.3'

    }
}

我的配置

grails.config.locations = [ "classpath:${appName}-config.properties"]
grails.project.groupId = appName // change this to alter the default package name and Maven publishing destination
grails.mime.file.extensions = true // enables the parsing of file extensions from URLs into the request format
grails.mime.use.accept.header = false

grails.mime.types = [ html: ['text/html','application/xhtml+xml'],
    xml: ['text/xml', 'application/xml'],
    text: 'text/plain',
    js: 'text/javascript',
    rss: 'application/rss+xml',
    atom: 'application/atom+xml',
    css: 'text/css',
    csv: 'text/csv',
    all: '*/*',
    json: ['application/json','text/json'],
    form: 'application/x-www-form-urlencoded',
    multipartForm: 'multipart/form-data'
]


grails.resources.adhoc.patterns = ['/images/*', '/css/*', '/js/*', '/plugins/*','/font/*']
grails.resources.adhoc.includes = ['/images/**', '/css/**', '/js/**', '/plugins/**','/font/**']
grails.resources.rewrite.css = false


grails.views.default.codec = "html" // none, html, base64
grails.views.gsp.encoding = "UTF-8"
grails.converters.encoding = "UTF-8"

grails.views.gsp.sitemesh.preprocess = true

grails.scaffolding.templates.domainSuffix = 'Instance'


grails.json.legacy.builder = false
grails.enable.native2ascii = true
grails.spring.bean.packages = []
grails.web.disable.multipart=false

// request parameters to mask when logging exceptions
grails.exceptionresolver.params.exclude = ['password']

// enable query caching by default
grails.hibernate.cache.queries = true

经过测试:

grails版本:2.3.7,2.3.11,2.4.2

tomcat版本:7.0.26,7.0.54

linux和windows

编辑: 2014-07-13 16:00 CEST

仅当我使用放置在配置 / pardus中的过滤器类时才会出现问题。上次更改:asyncAuditService。

    package pardus

import javax.servlet.http.HttpServletResponse

class TermFilters {
    def springSecurityService
    def auditService
    def sessionRegistry

    def asyncAuditService

    def filters = {
        all(controller:'*', action:'*') {

            before = {

                ((HttpServletResponse) response).setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
                log.info "username ${session}"
                log.info "session user ${session.user}"
                log.info "ip address: ${request.getHeader("X-Real-IP")}"
                log.info "all: ${sessionRegistry.getAllPrincipals()}"

                def allowAlwaysController = ["login","info","logout"]



                def user = springSecurityService.currentUser

                if(user!=null && !user.enabled && !controllerName.equals('logout')){
                    redirect(controller:'logout');   
                    return false;                 
                }


                if (!springSecurityService.isLoggedIn() && !controllerName.equals('login')){

                    redirect(controller:'login');                    
                    return false;
                }

                if (session.is_confirmed!="true" && !controllerName.equals('info') && !controllerName.equals('login') && !controllerName.equals('logout')){
                    log.info('not confirmed');
                    redirect(controller:'info',action:'term');
                    return false;
                }


                log.info "password o: ${user?.passwordExpired}"
                if(!controllerName.equals('account') && session.is_confirmed=="true" && user!=null && (user.changePasswordReq || user.isMyPasswordExpired()) && !controllerName.equals('info') && !controllerName.equals('login') && !controllerName.equals('logout')){
                    log.info "password o: ${user.passwordExpired}"
                    flash.error = "NEW_PASSWORD_REQUIED"
                    redirect(controller:'account',action:'index');
                    return false;                    
                }

                if(!allowAlwaysController.contains(controllerName)){
                    def role = springSecurityService.currentUser?.getRole()?.authority
                    log.info "controllerName " + controllerName
                    log.info "controllerName " + actionName
                    if(role!=null && (grailsApplication.config.pardus.priv[role][controllerName]==null || !grailsApplication.config.pardus.priv[role][controllerName].contains(actionName))){
                        if(controllerName!="")
                        flash.error = "BRAK_UPRAWNIEN"
                        // todo: loguj incydent bezpieczenstwa
                        log.info "brak uprawnien"
                        redirect(controller:'dashboard',action:'index');
                        return false;                    
                    }

                }

                if(grailsApplication.config.pardus.audit){                  
                    asyncAuditService.audit(params,request.getHeader("X-Real-IP"),session,request.getHeader("user-agent"))
                }


            }
            after = { Map model ->

            }
            afterView = { Exception e ->


            }

        }
    }
}

0 个答案:

没有答案