• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Spring Northwest Usergroup Grails Presentation
 

Spring Northwest Usergroup Grails Presentation

on

  • 1,895 views

This is a presentation I gave at the Spring Northwest Usergroup (Manchester) 01/12/2009 . I quickly go over the basics of grails / groovy and then demonstrate using Spring AOP in grails showing how ...

This is a presentation I gave at the Spring Northwest Usergroup (Manchester) 01/12/2009 . I quickly go over the basics of grails / groovy and then demonstrate using Spring AOP in grails showing how easy it is to use your existing spring beans and spring projects.

Statistics

Views

Total Views
1,895
Views on SlideShare
1,888
Embed Views
7

Actions

Likes
0
Downloads
27
Comments
0

1 Embed 7

http://www.slideshare.net 7

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Spring Northwest Usergroup Grails Presentation Spring Northwest Usergroup Grails Presentation Presentation Transcript

    • Grails Presentation
      Adam Evans
      (http://www.ctisn.com)
    • What is Grails?
      Rapid development framework
      Convention over configuration
      Built on proven technologies
      Spring IoC
      Spring MVC
      Hibernate
      Sitemesh
      Uses groovy
    • What is Groovy?
      A scripting language which runs on the JVM
      Groovy Objects extend java.lang.Object
      Seamless Java integration
      Designed for the Java developer
      Linear learning curve
      Familiar syntax
    • A Java Class
    • And A Groovy Example
    • What's The Difference
      NONE!
      Groovy lets you use Java code in your groovy classes / scripts
      We can make this groovier
    • A Groovy Example V2
      No constructor – groovy allows you to pass in a map to set variables
      Closures (the each function)
      Null safe operations '?'
      Extends standard JDK classes objects (the each function)
      Typing optional – def keyword
    • Groovy
      Allows you to use Java + Static typing when necessary
      Adds additional functionality to standard JDK classes
      Closures
      MOP Meta Object Protocol
      Java like syntax
      Linear learning curve, you can start with Java and re-factor to make it groovier
    • Grails
      Uses best practices with the power of Groovy to make a rapid development environment built on proven technologies you already know
    • Grails Cont
      Provides 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 feature
      The grails app structure
    • Grails Plugins
      Provide a full slice of the application
      Views
      Controllers
      Domain objects
      Sessions
      Scripts
      Allow to make a application modular, great for teams working on feature sets and to reuse ability
    • Demo
      Lets take a look at how easy it is to create a grails application and integrate spring libraries
      We'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 line
      We 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 return
      a 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
    • Complete
      We now have a basic web application displaying results from the twitter api
    • Demo (cont)
      Run 'grails-stats'
      18 lines of code !
    • Integrating with Spring
      We've not interacted with Spring directly so far
      Grails has taken over in the background configuring the view resolver, url mappings / controllers for Spring MVN, injecting session beans
    • Spring In Grails
      We'll look at making further use of Spring in Grails by using Spring AOP to cache the search results
    • Spring AOP In Grails
      1) We place the required lib directory
      aspectjrt.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 Annotation
      We create a Cacheable annotation under src/java.
    • We create a Aspect
      With 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 Caching
      As we apply 'around' advice to our method it is trivial to cache.
      Check if we have a cached value
      If not execute method and store result
      else load cached item
      Return result
      For 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
    • Conclusion
      We've seen how Grails integrates with
      Java
      Spring
      The rapidness of creating a application
      If you have a spring application already you can import your spring beans into Grails
      Boilerplate code has gone, no more days lost setting up new projects writing masses of XML
    • Points not Discussed
      Scaffolding
      Grails attempts to create basic views of your domain to get you started
      GORM
    • Questions