Hello community, With all my projects, as I have ...
# questions
u
Hello community, With all my projects, as I have them pretty much the similar major dependencies, • spring security • spring security rest • db migration • spring data • spring session • redis • json view After upgrading to Grails 7, my GSP views just can not being loaded correctly with standalone war file. However the GSP views does work under development mode. Spending quite some time tracing the code, I found the
precompiledGspMap
was not being populated for groovyPageLocator bean, as fall back it tried to use
resourceLoader
to load the
gsp
and then render it. That's why it works in development mode(because it use
resourceLoader
anyway for development mode) I have to do the following work around to put the code in resource.groovy to make the whole project working with grails 7.0.2.
Copy code
// Force precompiledGspMap to be used in production
    // Override the groovyPageLocator bean from GroovyPagesGrailsPlugin
    // to force loading of precompiled GSPs even when Metadata thinks dev is available
    if (Environment.current == Environment.PRODUCTION && !Environment.isDevelopmentMode()) {
        groovyPageLocator(org.grails.web.gsp.io.CachingGrailsConventionGroovyPageLocator) { bean ->
            bean.lazyInit = true

            // Force loading of precompiled GSP map from gsp/views.properties in WEB-INF/classes
            precompiledGspMap = { org.springframework.beans.factory.config.PropertiesFactoryBean pfb ->
                ignoreResourceNotFound = true
                location = 'classpath:gsp/views.properties'
            }

            reloadEnabled = false
            cacheTimeout = -1  // Never expire cache
        }

        // Force messageSource to load from classpath in production
        // Override to ensure i18n message bundles are loaded from WEB-INF/classes
        messageSource(org.springframework.context.support.ReloadableResourceBundleMessageSource) {
            basename = 'classpath:messages'
            defaultEncoding = 'UTF-8'
            fallbackToSystemLocale = false
            useCodeAsDefaultMessage = false
            cacheSeconds = -1  // Cache forever in production
        }
    }
After putting this at the bottom of the resource.groovy. Everything works. I still doing the testing. Question is why do I have to do this? What is wrong? Obviously with simpler projects generated by the grails forge, it works perfectly too.
j
Have you updated the configuration for sitemesh to layout? I've had these issues when I forget to update the config settings (like the default layout name, etc)
u
No, I did not. I tried to switch to sitemesh3, but then I rolled it back to use layout again. (the only thing I changed was in the build.gradle, put sitemesh3 and remove the layout) I can give it a try with sitemesh3 again. Where is the document I can follow?
Copy code
implementation "org.apache.grails:grails-layout"
Thanks
specifically the property changes part
🙌 1
❤️ 1