【问题标题】:Grails3 with application.groovy shows mangled pages in Tomcat带有 application.groovy 的 Grails3 在 Tomcat 中显示了损坏的页面
【发布时间】:2016-05-14 07:15:32
【问题描述】:

我创建了一个 Grails 3(.1.0) 应用程序。

当我执行以下步骤时:

  • 将默认的application.yaml 替换为等效的application.groovy
  • 生成战争文件
  • 在 Tomcat 8(.0.30) 中部署战争文件
  • 打开申请页面 (http://localhost:8080)

然后我得到一个缺少所有样式和javascript的页面。

我做错了什么? 我的application.groovy 有问题吗?

grails {
    profile = "web"
    codegen {
        defaultPackage = "empty31"
    }
}

info {
    app {
        name = 'empt31'
        version = '0.1'
        grailsVersion = '3.1.0'
    }
}

spring {
    groovy {
        template['check-template-location'] = false
    }
}

server {
    contextPath = '/empty31'
}

grails {
    mime {
        disable {
            accept {
                header {
                    userAgents = ['Gecko', 'WebKit', 'Presto', 'Trident']
                }
            }
        }

        types {
            all = '*/*'
            atom = 'application/atom+xml'
            css = 'text/css'
            csv = 'text/csv'
            form = 'application/x-www-form-urlencoded'
            html = ['text/html', 'application/xhtml+xml']
            js = 'text/javascript'
            json = ['application/json', 'text/json']
            multipartForm = 'multipart/form-data'
            rss = 'application/rss+xml'
            text = 'text/plain'
            hal = ['application/hal+json', 'application/hal+xml']
            xml = ['text/xml', 'application/xml']
        }
    }
    urlmapping {
        cache {
            maxsize = 1000
        }
    }
    controllers {
        defaultScope = 'singleton'
    }
    converters {
        encoding = 'UTF-8'
    }
    views {
        'default' { codec = 'html' }
        gsp {
            encoding = 'UTF-8'
            htmlcodec = 'xml'
            codecs {
                expression = 'html'
                scriptlets = 'html'
                taglib = 'none'
                staticparts = 'none'
            }
        }
    }
}

endpoints {
    jmx['unique-names'] = true
}

hibernate {
    cache {
        queries = false
        use_second_level_cache = true
        use_query_cache = false
        region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory'
    }
}

dataSource {
    pooled = true
    jmxExport = true
    driverClassName = "org.h2.Driver"
    username = 'sa'
    password = ''
}

environments {
    development {
        dataSource {
            dbCreate = 'create-drop'
            url = 'jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE'
        }
    }
    test {
        dataSource {
            dbCreate = 'update'
            url = 'jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE'
        }
    }
    production {
        dataSource {
            dbCreate = 'update'
            url = 'jdbc:h2:./prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE'
            properties {
                jmxEnabled = true
                initialSize = 5
                maxActive = 50
                minIdle = 5
                maxIdle = 25
                maxWait = 10000
                maxAge = 600000
                timeBetweenEvictionRunsMillis = 5000
                minEvictableIdleTimeMillis = 60000
                validationQuery = 'SELECT 1'
                validationQueryTimeout = 3
                validationInterval = 15000
                testOnBorrow = true
                testWhileIdle = true
                testOnReturn = false
                jdbcInterceptors = 'ConnectionState'
                defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
            }
        }
    }
}

【问题讨论】:

    标签: tomcat grails grails-3.0


    【解决方案1】:

    如果你恢复到 application.yml 会发生什么?

    【讨论】:

    • 今天我正在测试两个版本(.groovy 和 .yml)并在 Chrome DevTools 面板打开的情况下添加屏幕截图。但是我们支持的其他软件的问题占用了我所有的时间。将在星期一进一步测试。
    【解决方案2】:

    您的资产管道似乎出了点问题。尝试 grails run-app 或直接运行 war - 如果可行,那可能是我们曾经通过跳过 grails 版本(从 3.0.3 到 3.0.7)避免的资产管道错误。

    您也可以尝试使用 grails.assets.bundle=false 禁用捆绑,看看是否有帮助;)

    检查你的 gradle.build

    apply plugin: "asset-pipeline"
    
    assets {
        minifyJs = true
        minifyCss = true
    }
    
    dependencies {
        ...
        runtime "org.grails.plugins:asset-pipeline"
        ...
    }
    

    如果恢复到 application.yml 解决问题也会很有趣,因为这个错误可能发生在我们引入 spring 安全核心插件的时候,它带来了 application.groovy 开箱即用......

    EDIT1: 这是我们目前正在使用的资产版本

    buildscript {
        dependencies {
            classpath 'com.bertramlabs.plugins:asset-pipeline-gradle:2.0.20'
        }
    }
    
    plugins {
        id 'com.bertramlabs.asset-pipeline' version '2.5.0'
    }
    

    【讨论】:

    • grails run-app 工作正常。我还尝试回到资产插件 3.0.1 作为解决 grails 问题的建议,但这没有帮助。将尝试 grails.assets.bundle=false
    • 我在 application.groovy 中添加了 grails.assets.bundle=false,但结果还是一样
    • 恢复到 application.yml 并不是一个真正的选择,因为我们希望将 joda-time 插件用作 sprint-security-core 插件。至少对于 joda-time 插件,我不知道如何使用 .yml 映射“用户类型”映射(因为它默认是闭包)
    • 我编辑了我的“答案,因为配置对于评论来说有点大;)
    • 为什么不同时使用ymlgroovy?只需使用原始 yml 和附加 application.groovy 进行 joda 配置
    猜你喜欢
    • 2017-09-22
    • 1970-01-01
    • 2016-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多