Home » Grails » Grails Bootstrap – Under the hood

Grails Bootstrap – Under the hood

In this post I shall give an overview of sequence of events that happens during bootstrapping of Grails application

Bootstrap can be divided into following 4  steps from conceptual point of view

  • Loading Plugins and init grailsApplication(Implementation of GrailsApplication Interface  )
  • Create Parent Application Context
  • Create Grails Root Application Context
  • Create WebAppliationContext for GrailsDispatcherServlet

Below is diagrammatic representation of same



Lets look at each of above steps in details

Loading Plugins and GrailsApplication

Before talking about workflow of loading plugins,  I want briefly discuss Gant Scripts

 Gant Scripts

  • These are essentially Groovy wrapper around ant scripts.They support concept of targets and dependencies
  • Grails searches for these scripts in below directories
    • USER_HOME/.grails/scripts
    • PROJECT_HOME/scripts
    • PROJECT_HOME/plugins/*/scripts
    • GRAILS_HOME/scripts
  • when you run any grails command example.-  grails run-app, it will search for RunApp.groovy in above directories and execute default target in that script
  • Scripts which do not have ‘_’ ( underscore) in their name,  have a default target and can be run using grails command
    • examples – RunApp, CreateScript,CreateService etc
  • Any script whose  name begins with ‘_’ (underscore) are internal scripts, i.e they  are used by other scripts, and do not have default target
    • example  –  _PluginDependencies.groovy, _PackagePlugins.groovy etc
  • include keyword specifies other scripts to be included in particular script
  • depends keyword executes target from other script.

More about Gant scripts can be found here

Now lets look at the workflow. It can be represented by below diagram



Workflow Key Points

  • There are 4 main Gant scripts shown in workflow – RunApp.groovy, _GrailsPackage.groovy, _PluginDependencies.groovy, _GrailsRun.groovy
  • Each box in diagram represents target which is being executed
  • Sequence of action is represented by arrows . Dashed line indicates return to caller script
  • RunApp.groovy is called when you run command , grails run-app ($GRAILS_HOME/scripts/RunApp.groovy)
  • RunApp has dependency named packageApp( from _GrailsPackage.groovy) . Two important targets called by packageApp are
    • loadPlugins
      • it initializes Java Objects DefaultGrailsApplication, DefaultGrailsPluginManager (if you want profile time taken to load individual plugins, you could set enableProfile to true and it will load ProfilingGrailsPluginManager)
      • loads individual plugins  and  stores  them as list in DefaultPluginManager
      • perform artefactConfigurations for  plugins . (Artefacts are resources that fulfil some  convention eg Controller, Services.)
      • initializes  grailsApplication
        • populatingAllClasses – essentially store all the classes which are loaded in a variable
        • ConfigureLoadedClasses
          • initialize Artifact Handlers  – eg. ControllerArtefactHandler, ServiceArtefactHandler etc…
          • inspect loaded classes and determine which ones are artefacts
    • generateWebXML
      • calls doWebDescriptor for each plugin
      • Generates web.xml  and stores it @  /USER_HOME/.grails/2.1.1/projects/PROJECT_NAME/resources
  • Finally runApp is called which starts Embeded TomcatServer

Root Application Context

When  GrailsContextLoader loads and below are 3 steps performed by it

  • Create  Parent Application Context
  • Create  Root Application Context
  • Execute Grails Bootstrap classes

Lets look at second step above in more details .



Below are key Points

  • create WebRunTimeSpringConfig
    • Generation of Spring Config at runtime
  • registerProvidedArtifacts – register Precompiled Artifacts
  • pluginManager.doRunTimeSpringConfig
    • Hook into Grails runtime configuration, configure beans.
    • run closure doWithSpring associated with each plugin
  • InitApplicationContext
    • Create GrailsApplicationContext
  • RegisterBeans
    • Register BeanConfigs,BeanNames, Aliases with BeanRegistry.
  • Refresh the context created
  • pluginManager.doDynamicMethods
    • register dynamic methods with any classes based on some criteria (inspect properties, add new methods for benchmarking etc)
  • pluginManager.doPostProcessing
    • execute doWithApplicationContext associated with each plugin

WebApplicationContext and GrailsDispatcherServlet

This is the last step before application launches. Key points regards this

  • an instance of GrailsDispatcherServlet is created
  • Initialize and configure WebApplicationContext . Below are strategies initialized  for default settings
    • MultiPartResolver – ContentLengthAwareCommonsMultipartResolver
    • LocalResolver – SessionLocaleResolver
    • ThemeResolver – FixedThemeResolver
    • HandlerMapping
      • GrailsControllerHandlerMapping
      • RequestMappingHandlerMapping
    • HandlerAdapters
      • RequestMappingHandlerAdapter
      • SimpleControllerHandlerAdapter
    • HandlerExceptionResolver – GrailsExceptionResolver
    • ViewNameTranslator – DefaultRequestToViewNameTranslator
    • ViewResolvers – ScaffoldingViewResolver
    • FlashMapManager – SessionFlashMapManager.

You can read about DispatcherServlet in one of my other article. Once above step is complete , application is ready to run.

A good presentation about architecture of Grails can be found here . Presentation is old, but core-concepts are explained very elegantly.


  1. vamsi v says:

    Very useful, I am impressed by your in depth coverage. I want to develop some short tutorials in line with Rails Casts. Would you like to help/ partner with me. thanks. (vamsi v)

  2. vamsi v says:

    Thanks for responding, my email is viz.ply@gmail.com, I live in Dallas, TX.
    Please send in the email with your contact info and I shall put together some details.

  3. Akshay says:

    Good description and explanation
    but i am lacking inline comparison of Grails with Spring MVC
    i believe these two are conceptually same for some initial only
    and your posted URL – http://www.slideshare.net/hominhchuc/graemerocher-grailsplug-inarchitecture-presentation
    is not working; kindly rectify and/or correct t this


  4. I do not even know how I ended up here, but I thought this post was great.
    I do not know who you are but certainly you’re going to a famous blogger if you aren’t already ;) Cheers!

  5. fantastic put up, very informative. I ponder why the other specialists of this sector do not understand this.
    You should continue your writing. I’m confident, you have a huge readers’ base already!

  6. It’s amazing to pay a quick visit this site and reading
    the views of all friends regarding this piece of writing, while
    I am also zealous of getting familiarity.

  7. You need to be a part of a contest for one of the highest quality sites
    on the internet. I will recommend this blog!

  8. Heya i am for the first time here. I found this board and
    I find It truly helpful & it helped me out a lot. I’m hoping
    to offer one thing back and aid others such as you helped me.

  9. Exceellent site. Plenty of helpful information here.
    I’m sending it to some buddies ans also sharing in delicious.

    And obviously, thank you in your effort!

  10. I every time spent my half an hour to read this webpage’s posts all the
    time along with a cup of coffee.

  11. Keep at heart that such problems could not entirely
    be avoid when it involves website hosting and thus companies
    which are punctual in setting up such things are
    in reality recommended. However, communication through telephones was more pricey.
    It is without stating that you’re going to spend many hours or simply could
    possibly be sometimes days suitable for comparing features and deciding about the best web service provider.

  12. First of all; Host – Gator is digit in the most trusty
    scheme contains discover there, and which is not without
    a reason. If you use a large amount of traffic, be sure to have enough server space and
    bandwidth to take care of it without ridiculous overage charges.
    Bandwidth usage mostly fluctuates so its preferable to always buy a limit higher
    then of actual usage.

  13. Oh my goodness! Incredible article dude! Thank you, However I am going through issues with your RSS.
    I don’t understand the reason why I cannot join it.
    Is there anybody else having the same RSS problems?
    Anyone who knows the answer can you kindly respond? Thanks!!

  14. Niice weblog right here! Additionally your site lots up very fast!
    What host are you the usage of? Can I am getting youjr associate hyperlink for your host?
    I want myy site loaded up as fast as yours lol

  15. Great post. I was checking continuously this blog and I’m impressed!
    Very useful info particularly the closing phase :) I maintain such info a lot.

    I was seeking this particular info for a long time. Thank you and good luck.

  16. HCG Diet says:

    The proper day for taking the urine test is approximately 2 weeks after having an unprotected sexual contact.
    What do you expect long-term not just short-term as far as
    an acceptable return on your investment. It is released by
    the placenta when the fertilized egg is implanted in the uterus.

  17. Spot on with this write-up, I truly believe this site needs far more attention.
    I’ll probably be returning to read through more,
    thanks for the advice!

  18. Philip says:

    At this time it looks like WordPress is the preferred
    blogging platform out there right now. (from what I’ve read)
    Is that what you are using on your blog?

  19. It can significantly increase cardio respiratory fitness.
    Think about the demographic of the user, the size of the space and of course
    the budget. Their club provides a huge state of the art equipment,
    saunas, masseurs, nutritionists, beauty therapists and the best personal training programs
    which will help you to get the best out of them.

  20. bing.Com says:

    Thank you for sharing your info. I truly appreciate
    your efforts and I will be waiting for your further post thanks once again.

  21. I every time spent my half an hour to read this weblog’s articles every day along with a cup of coffee.

  22. domain says:

    hi!,I like your writing so a lot! share we keep up
    a correspondence more approximately your article on AOL?
    I require an expert on this house to solve my problem.
    Maybe that’s you! Taking a look ahead to see you.

  23. It’s hard to find knowledgeable people on this subject, however, you sound like you know what you’re talking about!

  24. Italy Pride says:

    Hello, I think your blog might be having browser compatibility issues.
    When I look at your blog in Safari, it looks fine but when opening in Internet Explorer,
    it has some overlapping. I just wanted to give you a quick heads up!
    Other then that, awesome blog!

  25. If some one wants expert view concerning blogging afterward i suggest him/her to go to see this
    web site, Keep up the nice job.

  26. Woah! I’m really enjoying the template/theme of this website.
    It’s simple, yet effective. A lot of times it’s tough to get that “perfect balance”
    between superb ueability and visual appearance.
    I must say you have done a amazing job with this. Additionally, the blog loads very quick for me on Internet explorer.
    Outstanding Blog!

  27. Hey there, I think your website might be having browser compatibility issues.
    When I look at your website in Ie, it looks fine
    but when opening in Internet Explorer, it has some
    overlapping. I just wanted to give you a
    quick heads up! Other then that, terrific blog!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: