Skip to content

Commit

Permalink
spring run command removed in 3.x, convert app.groovy to standalone g…
Browse files Browse the repository at this point in the history
…roovy script
  • Loading branch information
codeconsole committed Nov 12, 2024
1 parent 737a353 commit e075294
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion sample-apps/gsp/script/.sdkmanrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
java=17.0.12-librca
groovy=4.0.24
groovy=4.0.23
springboot=3.3.5
5 changes: 3 additions & 2 deletions sample-apps/gsp/script/README.md
Original file line number Diff line number Diff line change
@@ -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
```
28 changes: 26 additions & 2 deletions sample-apps/gsp/script/app.groovy
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,7 +23,7 @@ class GspController {
@RequestMapping("/")
ModelAndView home() {
new ModelAndView('index', 'name', 'world')
}
}
}

@Component
Expand All @@ -19,4 +32,15 @@ class FormatTagLib {
def dateFormat = { attrs, body ->
out << new SimpleDateFormat(attrs.format).format(attrs.date)
}
}
}

@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)
1 change: 0 additions & 1 deletion sample-apps/gsp/script/application.properties
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e075294

Please sign in to comment.