Prev Next

API / Apache Grails Interview questions

Explain the sequence of events when a GSP page is rendered?

The first time a given GSP is requested, Grails has to compile it into executable code; subsequent requests reuse that compiled form, which is why GSP rendering is fast in steady-state despite starting from a template file rather than pre-compiled code.

sequenceDiagram participant Controller participant ViewResolver as View Resolver participant GSPEngine as GSP Engine participant Model as Request model Controller->>ViewResolver: Return model, implicit view name ViewResolver->>ViewResolver: Locate matching .gsp file by convention ViewResolver->>GSPEngine: Request compiled view for this GSP alt GSP not yet compiled (or changed) GSPEngine->>GSPEngine: Parse GSP into a Groovy class (page as code) GSPEngine->>GSPEngine: Cache the compiled class else Already compiled GSPEngine->>GSPEngine: Reuse cached compiled class end GSPEngine->>Model: Bind model attributes into page scope GSPEngine->>GSPEngine: Execute compiled page, resolving tags (g:each, g:link, etc.) GSPEngine-->>Controller: Stream resulting HTML to the response

The view resolver locates the correct .gsp file by the same controller/action naming convention used for URL mapping, then hands it to the GSP engine, which compiles the template into an actual Groovy class the first time it's needed (or whenever the source file changes, in development), caching that compiled form for subsequent requests. Once compiled, rendering is simply executing that class against the model data the controller returned, resolving any tag library calls (g:each, g:link, custom tags) along the way, and streaming the resulting HTML to the response.

This compile-once, reuse-many-times behavior is why GSP rendering doesn't re-parse the template file on every single request in production — the expensive parsing step only happens once per template (or once per change, during active development with hot-reload enabled).

What does the GSP engine do the very first time a particular GSP file is requested?
Why doesn't GSP rendering re-parse the template file on every single request in production?

More Related questions...

What is Apache Grails? What is GORM? What is a Grails domain class? What is a Grails controller? What is a Groovy Server Page (GSP)? What is convention-over-configuration in Grails? What is a dynamic finder in GORM? What is Grails Forge? What is the Grails Wrapper (grailsw)? What is a Grails service? What are the types of environments Grails supports? What is scaffolding in Grails? What is a Grails plugin? Define GORM Data Services? How do you create a new Grails application using Grails Forge? Why did Grails move under the Apache Software Foundation? Why do we use GORM instead of writing raw SQL/JDBC? How does Grails apply convention-over-configuration to map URLs to controllers? What is the difference between Grails 7 and Grails 8? When should you use GORM Data Services instead of dynamic finders? What is the difference between a dynamic finder and a criteria query? What happens when a domain class fails validation in Grails? What is the difference between a Grails controller and a Grails service? Which is better for a new project in 2026: Grails 7 or Grails 8, and why? How can you optimize GORM queries to avoid the N+1 problem? How do you troubleshoot a LazyInitializationException in a Grails application? Explain the lifecycle of a request in a Grails application? Explain the execution flow of a GORM save() call under the hood? Explain the internal working of GORM Data Services? What is the difference between an interceptor and a filter in Grails? Why should you mark long-running database work with @Transactional at the service layer? What is a Grails command object? How does Grails integrate with Spring Security? What is the difference between static and dynamic scaffolding in Grails? How does Grails support internationalization (i18n)? Explain the internal working of Grails' convention-based URL mapping? What is the difference between Grails profiles like "web" and "rest-api"? How do you enforce validation constraints on a Grails domain class? What is the role of the asset-pipeline plugin in Grails? How does Grails support database migrations? Explain the sequence of events when a GSP page is rendered? What is the difference between GORM criteria queries and HQL? How do you configure multi-tenancy in a Grails application with GORM? What is the difference between Grails' component model and Spring Boot's plain REST controller approach? Explain how Grails' dependency injection works with Spring beans? How do you write unit and integration tests for a Grails application? What is the difference between unit tests and integration tests in Grails testing? Explain the internal working of a GORM dynamic finder at runtime? What is the difference between Apache Grails and Ruby on Rails? Explain how GORM's optimistic locking prevents concurrent update conflicts?
Show more question and Answers...


Comments & Discussions