From e0752940909daec11c58280c229020d2065125b0 Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Mon, 11 Nov 2024 23:00:12 -0800 Subject: [PATCH] spring run command removed in 3.x, convert app.groovy to standalone groovy script --- README.md | 2 +- .../grails/gsp/boot/GspAutoConfiguration.java | 3 +- sample-apps/gsp/script/.sdkmanrc | 2 +- sample-apps/gsp/script/README.md | 5 ++-- sample-apps/gsp/script/app.groovy | 28 +++++++++++++++++-- sample-apps/gsp/script/application.properties | 1 - 6 files changed, 33 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c34d70a..c9315ef 100644 --- a/README.md +++ b/README.md @@ -15,5 +15,5 @@ To run Spring Boot Script App ```shell cd sample-apps/gsp/script sdk env - spring run app.groovy + groovy -Dgroovy.grape.report.downloads=true app.groovy ``` diff --git a/grails-gsp-spring-boot/src/main/java/grails/gsp/boot/GspAutoConfiguration.java b/grails-gsp-spring-boot/src/main/java/grails/gsp/boot/GspAutoConfiguration.java index 1ee30c0..9a6c314 100644 --- a/grails-gsp-spring-boot/src/main/java/grails/gsp/boot/GspAutoConfiguration.java +++ b/grails-gsp-spring-boot/src/main/java/grails/gsp/boot/GspAutoConfiguration.java @@ -113,11 +113,12 @@ protected static class GspTemplateEngineAutoConfiguration extends AbstractGspCon @Bean @ConditionalOnMissingBean(name="groovyPagesTemplateEngine") - GroovyPagesTemplateEngine groovyPagesTemplateEngine(TagLibraryResolver tagLibraryResolver, TagLibraryLookup tagLibraryLookup) { + GroovyPagesTemplateEngine groovyPagesTemplateEngine(TagLibraryResolver tagLibraryResolver, TagLibraryLookup tagLibraryLookup, GroovyPagesTemplateRenderer groovyPagesTemplateRenderer) { GroovyPagesTemplateEngine templateEngine = new GroovyPagesTemplateEngine(); templateEngine.setReloadEnabled(gspReloadingEnabled); templateEngine.setJspTagLibraryResolver(tagLibraryResolver); templateEngine.setTagLibraryLookup(tagLibraryLookup); + groovyPagesTemplateRenderer.setGroovyPagesTemplateEngine(templateEngine); return templateEngine; } diff --git a/sample-apps/gsp/script/.sdkmanrc b/sample-apps/gsp/script/.sdkmanrc index d114086..fdc46b9 100644 --- a/sample-apps/gsp/script/.sdkmanrc +++ b/sample-apps/gsp/script/.sdkmanrc @@ -1,3 +1,3 @@ java=17.0.12-librca -groovy=4.0.24 +groovy=4.0.23 springboot=3.3.5 diff --git a/sample-apps/gsp/script/README.md b/sample-apps/gsp/script/README.md index b90fa33..682de4b 100644 --- a/sample-apps/gsp/script/README.md +++ b/sample-apps/gsp/script/README.md @@ -1,5 +1,6 @@ -Use the following command with Spring Boot CLI 2.x +Use the following command with Groovy CLI 4.x ```shell -spring run app.groovy +sdk env +groovy -Dgroovy.grape.report.downloads=true app.groovy ``` \ No newline at end of file diff --git a/sample-apps/gsp/script/app.groovy b/sample-apps/gsp/script/app.groovy index 0522e5b..d20da80 100644 --- a/sample-apps/gsp/script/app.groovy +++ b/sample-apps/gsp/script/app.groovy @@ -1,5 +1,18 @@ +package demo + @GrabResolver(name='grails-repo', root='https://repo.grails.org/grails/core/') @Grab("org.grails:grails-gsp-spring-boot:7.0.0-SNAPSHOT") +@Grab("org.grails:grails-plugin-controllers:7.0.0-SNAPSHOT") +// if you need to clear snapshots, they are saved to ~/.groovy/grapes + +import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.SpringApplication +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController +import org.springframework.stereotype.Component +import org.springframework.context.annotation.Bean +import grails.gsp.boot.GspAutoConfiguration +import org.springframework.boot.autoconfigure.ImportAutoConfiguration import grails.gsp.TagLib import org.springframework.web.servlet.ModelAndView @@ -10,7 +23,7 @@ class GspController { @RequestMapping("/") ModelAndView home() { new ModelAndView('index', 'name', 'world') - } + } } @Component @@ -19,4 +32,15 @@ class FormatTagLib { def dateFormat = { attrs, body -> out << new SimpleDateFormat(attrs.format).format(attrs.date) } -} \ No newline at end of file +} + +@SpringBootApplication +@ImportAutoConfiguration(GspAutoConfiguration.class) +class Application { + @Bean GspController rspController() { new GspController() } + @Bean FormatTagLib formatTagLib() { new FormatTagLib() } +} + +System.setProperty("org.springframework.boot.logging.LoggingSystem", "none") + +SpringApplication.run(Application) \ No newline at end of file diff --git a/sample-apps/gsp/script/application.properties b/sample-apps/gsp/script/application.properties index ee73950..ba4e13e 100644 --- a/sample-apps/gsp/script/application.properties +++ b/sample-apps/gsp/script/application.properties @@ -1,4 +1,3 @@ spring.gsp.templateRoots=classpath:/templates spring.main.allow-circular-references=true -grails.views.gsp.sitemesh.preprocess=false sitemesh.decorator.default=main \ No newline at end of file