SlideShare a Scribd company logo
Grails PresentationAdam Evans(http://www.ctisn.com)
What is Grails?Rapid development frameworkConvention over configurationBuilt on proven technologiesSpring IoCSpring MVCHibernateSitemeshUses groovy
What is Groovy?A scripting language which runs on the JVMGroovy Objects extend java.lang.ObjectSeamless Java integrationDesigned for the Java developerLinear learning curveFamiliar syntax
A Java Class
And A Groovy Example
What's The DifferenceNONE!Groovy lets you use Java code in your groovy classes / scriptsWe can make this groovier
A Groovy Example V2No constructor – groovy allows you to pass in a map to set variablesClosures (the each function)Null safe operations '?'Extends standard JDK classes objects (the each function)Typing optional – def keyword
GroovyAllows you to use Java + Static typing when necessaryAdds additional functionality to standard JDK classesClosuresMOP Meta Object ProtocolJava like syntaxLinear learning curve, you can start with Java and re-factor to make it groovier
GrailsUses best practices with the power of Groovy to make a rapid development environment built on proven technologies you already know
Grails ContProvides a view layer (GSP's + Sitemesh)Service layer (Service spring managed beans)Repository (GORM, Grails object relational mapping...hibernate abstraction)Unit / integration tests a key featureThe grails app structure
Grails PluginsProvide a full slice of the applicationViewsControllersDomain objectsSessionsScriptsAllow to make a application modular, great for teams working on feature sets and to reuse ability
DemoLets take a look at how easy it is to create a grails application and integrate spring librariesWe'll create a basic application to search twitter using the api, cache and display the results
Demo (contd)Create the application, type 'grails create-app twitter-search' from the command lineWe now have a fully functional web application, this can be run using 'grails run-app'
Demo (contd)Create a service bean to query twitter. 'grails create-service com.demo.TwitterService'
Demo (contd)Create a controller to query the service 'grails create-controller com.demo.TwitterSearch'Notes: 1) Spring injects the TwitterService class based on the variable name 2) Controller actions are defined as groovy closures. We returna map to the view. By convention the view will be under 'grails-app/views/${controller}/${action}‘ Iefor the above:     'grails-app/views/twitterSearch/search.gsp'
Demo (cont)Create the view 'grails-app/views/twitterSearch/seach.gsp'Note: the layout meta tag, this tells sitemesh to decorate the page using the 'grails-app/layouts/main.gsp' template
CompleteWe now have a basic web application displaying results from the twitter api
Demo (cont)Run 'grails-stats'18 lines of code !
Integrating with SpringWe've not interacted with Spring directly so farGrails has taken over in the background configuring the view resolver, url mappings / controllers for Spring MVN, injecting session beans
Spring In GrailsWe'll look at making further use of Spring in Grails by using Spring AOP to cache the search results
Spring AOP In Grails1) We place the required lib directoryaspectjrt.jar (v1.5+) aspectjweaver.jar (v1.5+)2) Create the spring config xml file 'grails-app/conf/resources.xml'Note: As of grails 1.2 the component-scan will not be needed as grails supports the@Component annotation by default
Create a AnnotationWe create a Cacheable annotation under src/java.
We create a AspectWith the above, any method with the annotation @Cacheable will be handled by the aroundAdvice method. For now we just called proceed() so the method We are intercepting is executed and we return the value
Trivial CachingAs we apply 'around' advice to our method it is trivial to cache.Check if we have a cached valueIf not execute method and store resultelse load cached itemReturn resultFor this example grails comes with the oscache libs already so I'll use that for the caching
Trivial Caching (cont)
Trivial Caching (cont)Below is the function we use to generate the cache key based on method name / arguments
ConclusionWe've seen how Grails integrates withJavaSpringThe rapidness of creating a applicationIf you have a spring application already you can import your spring beans into GrailsBoilerplate code has gone, no more days lost setting up new projects writing masses of XML
Points not DiscussedScaffoldingGrails attempts to create basic views of your domain to get you startedGORM
Questions

More Related Content

PDF
ServiceWorkerとES6 Modules時代のTypescript開発考察
PPT
Griffon: Swing just got fun again
ODP
Grails Internals Ggug Dec 2009
PPTX
Node js with steroids
PDF
GR8Conf 2015 - Spring Boot and Groovy. What more do you need?
PDF
Golang for PHP Developers: Dependency management with Glide
PDF
Use groovy & grails in your spring boot projects
PDF
Grunt training deck
ServiceWorkerとES6 Modules時代のTypescript開発考察
Griffon: Swing just got fun again
Grails Internals Ggug Dec 2009
Node js with steroids
GR8Conf 2015 - Spring Boot and Groovy. What more do you need?
Golang for PHP Developers: Dependency management with Glide
Use groovy & grails in your spring boot projects
Grunt training deck

What's hot (20)

PPTX
The State of the Developer Ecosystem - .NET Conf Barcelona 2018
PPTX
Building robust REST APIs
PDF
GradleのREPLプラグイン紹介 #jggug
PDF
Nikolai Boiko "NodeJS Refactoring: How to kill a Dragon and stay alive"
PDF
Intro to javascript (4 week)
PDF
Dockerized apps on Kubernetes
PDF
Introducing spring
PPTX
Grails Spring Boot
PDF
Angular 2 observables
PDF
2016 05-cloudsoft-amp-and-brooklyn-new
PPT
Griffon Presentation
PDF
GitLab Frontend and VueJS at GitLab
PDF
Cloud Spin - building a photo booth with the Google Cloud Platform
PPS
Groovy & Grails
PDF
Github Actions in action - GHA in OSS project (instead of Travis)
PPTX
GWTcon 2015 - Best development practices for GWT web applications
PDF
Jedi knight
PDF
Node & Express as Workflow Tools
ODP
Jenkins and rails app - Le Dinh Vu
ODP
Eclipse Buildship DemoCamp Hamburg (June 2015) with additional screenshots
The State of the Developer Ecosystem - .NET Conf Barcelona 2018
Building robust REST APIs
GradleのREPLプラグイン紹介 #jggug
Nikolai Boiko "NodeJS Refactoring: How to kill a Dragon and stay alive"
Intro to javascript (4 week)
Dockerized apps on Kubernetes
Introducing spring
Grails Spring Boot
Angular 2 observables
2016 05-cloudsoft-amp-and-brooklyn-new
Griffon Presentation
GitLab Frontend and VueJS at GitLab
Cloud Spin - building a photo booth with the Google Cloud Platform
Groovy & Grails
Github Actions in action - GHA in OSS project (instead of Travis)
GWTcon 2015 - Best development practices for GWT web applications
Jedi knight
Node & Express as Workflow Tools
Jenkins and rails app - Le Dinh Vu
Eclipse Buildship DemoCamp Hamburg (June 2015) with additional screenshots
Ad

Viewers also liked (14)

PPT
Cf Moto
PDF
Architecture Projects P
PPTX
Wytyczne do pisania programów
PPT
Egypt Vacation
PPSX
Participantes del dial a la nube
PDF
KEY
Recent Works
PDF
Making the case for Play Framework and Scala- Budapest Ping-Conf (2014)
PDF
AWS at Childrens in the BBC
KEY
Finding The Slope And Y Intercept
PPT
Red Black Trees
PPTX
How to engage, nurture and close more prospects with Full Funnel Marketing
PPTX
Referral hacks: 22 best practices to help you win more business
PPTX
Eight ways to double your sales team's productivity #b2bmx
Cf Moto
Architecture Projects P
Wytyczne do pisania programów
Egypt Vacation
Participantes del dial a la nube
Recent Works
Making the case for Play Framework and Scala- Budapest Ping-Conf (2014)
AWS at Childrens in the BBC
Finding The Slope And Y Intercept
Red Black Trees
How to engage, nurture and close more prospects with Full Funnel Marketing
Referral hacks: 22 best practices to help you win more business
Eight ways to double your sales team's productivity #b2bmx
Ad

Similar to Spring Northwest Usergroup Grails Presentation (20)

PPTX
Introduction to Grails 2013
PDF
Grails Integration Strategies
PDF
Grails 101
PPT
JavaOne 2008 - TS-5764 - Grails in Depth
PPTX
Grails Advanced
ODP
Groovy and Grails intro
PPT
Fast web development using groovy on grails
ODP
Groovygrailsnetbeans 12517452668498-phpapp03
PDF
Grails Launchpad - From Ground Zero to Orbit
POT
intoduction to Grails Framework
PDF
Grails 101
ODP
Agile web development Groovy Grails with Netbeans
PPT
Grails Introduction - IJTC 2007
PDF
Introduction To Groovy And Grails - SpringPeople
ODP
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English
PDF
GR8Conf 2011: Grails, how to plug in
PPT
Introduction To Grails
PDF
Grails 3.0 Preview
PPTX
Magic with groovy & grails
PPTX
Introduction to Grails Framework
Introduction to Grails 2013
Grails Integration Strategies
Grails 101
JavaOne 2008 - TS-5764 - Grails in Depth
Grails Advanced
Groovy and Grails intro
Fast web development using groovy on grails
Groovygrailsnetbeans 12517452668498-phpapp03
Grails Launchpad - From Ground Zero to Orbit
intoduction to Grails Framework
Grails 101
Agile web development Groovy Grails with Netbeans
Grails Introduction - IJTC 2007
Introduction To Groovy And Grails - SpringPeople
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English
GR8Conf 2011: Grails, how to plug in
Introduction To Grails
Grails 3.0 Preview
Magic with groovy & grails
Introduction to Grails Framework

Recently uploaded (20)

PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Machine learning based COVID-19 study performance prediction
PPT
Teaching material agriculture food technology
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Electronic commerce courselecture one. Pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Encapsulation_ Review paper, used for researhc scholars
Machine learning based COVID-19 study performance prediction
Teaching material agriculture food technology
Building Integrated photovoltaic BIPV_UPV.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Dropbox Q2 2025 Financial Results & Investor Presentation
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
20250228 LYD VKU AI Blended-Learning.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Review of recent advances in non-invasive hemoglobin estimation
NewMind AI Weekly Chronicles - August'25 Week I
Electronic commerce courselecture one. Pdf
cuic standard and advanced reporting.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
The Rise and Fall of 3GPP – Time for a Sabbatical?
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication

Spring Northwest Usergroup Grails Presentation

  • 2. What is Grails?Rapid development frameworkConvention over configurationBuilt on proven technologiesSpring IoCSpring MVCHibernateSitemeshUses groovy
  • 3. What is Groovy?A scripting language which runs on the JVMGroovy Objects extend java.lang.ObjectSeamless Java integrationDesigned for the Java developerLinear learning curveFamiliar syntax
  • 5. And A Groovy Example
  • 6. What's The DifferenceNONE!Groovy lets you use Java code in your groovy classes / scriptsWe can make this groovier
  • 7. A Groovy Example V2No constructor – groovy allows you to pass in a map to set variablesClosures (the each function)Null safe operations '?'Extends standard JDK classes objects (the each function)Typing optional – def keyword
  • 8. GroovyAllows you to use Java + Static typing when necessaryAdds additional functionality to standard JDK classesClosuresMOP Meta Object ProtocolJava like syntaxLinear learning curve, you can start with Java and re-factor to make it groovier
  • 9. GrailsUses best practices with the power of Groovy to make a rapid development environment built on proven technologies you already know
  • 10. Grails ContProvides a view layer (GSP's + Sitemesh)Service layer (Service spring managed beans)Repository (GORM, Grails object relational mapping...hibernate abstraction)Unit / integration tests a key featureThe grails app structure
  • 11. Grails PluginsProvide a full slice of the applicationViewsControllersDomain objectsSessionsScriptsAllow to make a application modular, great for teams working on feature sets and to reuse ability
  • 12. DemoLets take a look at how easy it is to create a grails application and integrate spring librariesWe'll create a basic application to search twitter using the api, cache and display the results
  • 13. Demo (contd)Create the application, type 'grails create-app twitter-search' from the command lineWe now have a fully functional web application, this can be run using 'grails run-app'
  • 14. Demo (contd)Create a service bean to query twitter. 'grails create-service com.demo.TwitterService'
  • 15. Demo (contd)Create a controller to query the service 'grails create-controller com.demo.TwitterSearch'Notes: 1) Spring injects the TwitterService class based on the variable name 2) Controller actions are defined as groovy closures. We returna map to the view. By convention the view will be under 'grails-app/views/${controller}/${action}‘ Iefor the above: 'grails-app/views/twitterSearch/search.gsp'
  • 16. Demo (cont)Create the view 'grails-app/views/twitterSearch/seach.gsp'Note: the layout meta tag, this tells sitemesh to decorate the page using the 'grails-app/layouts/main.gsp' template
  • 17. CompleteWe now have a basic web application displaying results from the twitter api
  • 19. Integrating with SpringWe've not interacted with Spring directly so farGrails has taken over in the background configuring the view resolver, url mappings / controllers for Spring MVN, injecting session beans
  • 20. Spring In GrailsWe'll look at making further use of Spring in Grails by using Spring AOP to cache the search results
  • 21. Spring AOP In Grails1) We place the required lib directoryaspectjrt.jar (v1.5+) aspectjweaver.jar (v1.5+)2) Create the spring config xml file 'grails-app/conf/resources.xml'Note: As of grails 1.2 the component-scan will not be needed as grails supports the@Component annotation by default
  • 22. Create a AnnotationWe create a Cacheable annotation under src/java.
  • 23. We create a AspectWith the above, any method with the annotation @Cacheable will be handled by the aroundAdvice method. For now we just called proceed() so the method We are intercepting is executed and we return the value
  • 24. Trivial CachingAs we apply 'around' advice to our method it is trivial to cache.Check if we have a cached valueIf not execute method and store resultelse load cached itemReturn resultFor this example grails comes with the oscache libs already so I'll use that for the caching
  • 26. Trivial Caching (cont)Below is the function we use to generate the cache key based on method name / arguments
  • 27. ConclusionWe've seen how Grails integrates withJavaSpringThe rapidness of creating a applicationIf you have a spring application already you can import your spring beans into GrailsBoilerplate code has gone, no more days lost setting up new projects writing masses of XML
  • 28. Points not DiscussedScaffoldingGrails attempts to create basic views of your domain to get you startedGORM