API / Apache Grails Interview questions
1. What is Apache Grails?
Apache Grails is an open-source, convention-over-configuration web application framework for the JVM, built on top of Spring Boot and written using the Groovy language (though Java can be mixed in freely). It was created by Graeme Rocher, with an initial release in October 2005, and was directly ...
2. What is GORM?
GORM (Grails Object Relational Mapping) is Grails' data access toolkit — a set of APIs and language extensions that let a plain Groovy class be persisted to a database with almost no boilerplate. Declaring a class as a domain class is usually enough: GORM automatically adds an id and a vers...
3. What is a Grails domain class?
A domain class is a plain Groovy class placed in an application's grails-app/domain directory, and that location convention alone is what tells Grails to treat it as a persistent entity managed by GORM. Its properties become database columns automatically: a class with a String title and a Person...
4. What is a Grails controller?
A controller is a Groovy class in grails-app/controllers whose public methods (or closures, in older style) automatically become request-handling actions , mapped to URLs by convention without any explicit routing code required for the common case. A class named BookController with an action meth...
5. What is a Groovy Server Page (GSP)?
A GSP is Grails' server-side view template format — an HTML file with embedded Groovy expressions and a rich library of custom tags, saved with a .gsp extension in grails-app/views , that renders dynamic content on the server before sending plain HTML to the browser. Groovy code embeds with...
6. What is convention-over-configuration in Grails?
Convention-over-configuration means the framework infers behavior from naming and file placement instead of requiring explicit configuration for the common case — the developer only has to configure something when they want to deviate from the sensible default. Convention What it means, wit...
7. What is a dynamic finder in GORM?
A dynamic finder is a query method that looks like an ordinary static method call — Book.findByTitle("Dune") — but doesn't actually exist anywhere in source code; GORM generates its implementation at runtime by parsing the method name itself. The pattern following findBy , findAllBy ,...
8. What is Grails Forge?
Grails Forge (at start.grails.org) is the current recommended starting point for a new Grails application — a web-based project generator conceptually similar to Spring Initializr, letting a developer pick options and download a ready-to-build project rather than relying solely on offline C...
9. What is the Grails Wrapper (grailsw)?
The Grails Wrapper is a small (about 25KB) distribution — a grailsw shell script, a grailsw.bat batch script, and a small jar — that manages exactly which Grails CLI version an application builds and runs with, the same role the Gradle Wrapper plays for Gradle. Available starting with...
10. What is a Grails service?
A service is a Groovy class in grails-app/services intended to hold business logic that doesn't belong directly in a controller or a domain class — the layer that coordinates persistence, validation, and any external calls behind a single, testable entry point. By convention, a class whose ...
11. What are the types of environments Grails supports?
Grails ships with three built-in environments — development , test , and production — each of which can carry its own configuration block (database connection, logging level, cache settings) inside the application's configuration file, so the same codebase behaves appropriately in eac...
12. What is scaffolding in Grails?
Scaffolding is Grails' feature for automatically generating a full working create/read/update/delete (CRUD) interface — controller actions and GSP views — for a domain class, based entirely on its properties and constraints, without a developer writing that boilerplate by hand. It com...
13. What is a Grails plugin?
A plugin is a packaged, reusable unit of functionality that extends a Grails application — anything from adding new artifacts (controllers, domain classes, tag libraries) to hooking into the application's startup lifecycle or wrapping an entire external library behind Grails-friendly conven...
14. Define GORM Data Services?
GORM Data Services, introduced in GORM 6.1, are an alternative to dynamic finders that let a developer declare a data access interface (or abstract class) and have GORM generate the real implementation at compile time, based purely on the method signatures declared. Writing one is a matter of cre...
15. How do you create a new Grails application using Grails Forge?
Visit start.grails.org and choose the application's group and package name, similar to filling out a form on Spring Initializr. Select a profile (such as "web" for a traditional server-rendered application or "rest-api" for a JSON-focused backend), which determines the base set of dependencies an...
16. Why did Grails move under the Apache Software Foundation?
Grails has changed stewards more than once over its life — originally driven by SpringSource/VMware/Pivotal, later by Object Computing Inc. (OCI) — and moving to the ASF addresses the recurring concern any framework tied to a single commercial sponsor eventually faces: what happens to...
17. Why do we use GORM instead of writing raw SQL/JDBC?
Raw JDBC requires a developer to manually write SQL, manage connections and statements, map result sets back into objects by hand, and coordinate transaction boundaries explicitly — a substantial amount of repetitive, error-prone plumbing for what's conceptually a simple "save this object" ...
18. How does Grails apply convention-over-configuration to map URLs to controllers?
By default, Grails derives a controller's base URL directly from its class name (stripped of the "Controller" suffix and lower-cased), and each public action method within it becomes a further path segment — no routing table has to be written for the common case to work. A class named Produ...
19. What is the difference between Grails 7 and Grails 8?
As of mid-2026, Grails 7.x is the current "Active Development" line that most production applications should be running, while Grails 8 is still in its milestone/preview stage, targeting a modernized dependency stack rather than a fundamentally different programming model. Grails 7.x Grails 8 Cur...
20. When should you use GORM Data Services instead of dynamic finders?
Dynamic finders are still perfectly reasonable for quick, one-off lookups scattered through application code, but GORM Data Services are the better choice once a query needs to be reliable, reused across the codebase, or verified before the application ever runs. Reach for a Data Service when: th...
21. What is the difference between a dynamic finder and a criteria query?
Both retrieve data through GORM without hand-written SQL, but they differ in how flexible and composable the resulting query can be, and in how the query is actually expressed in code. Dynamic finder Criteria query Query encoded in a method name string, e.g. findByTitleAndAuthor Query built progr...
22. What happens when a domain class fails validation in Grails?
Calling save() on a domain instance that violates one of its declared constraints doesn't throw an exception by default — instead, the save silently fails, the object is not persisted, and the instance is populated with errors describing exactly which constraints failed and why. The develop...
23. What is the difference between a Grails controller and a Grails service?
Both are Groovy classes managed by Grails' conventions, but they sit at different layers of the application and are responsible for fundamentally different concerns. Controller Service Location: grails-app/controllers Location: grails-app/services Handles HTTP requests, params binding, rendering ...
24. Which is better for a new project in 2026: Grails 7 or Grails 8, and why?
For a genuinely new project starting today, Grails 7 is the pragmatic default, and the reasoning is entirely about maturity rather than either version being the "wrong" technology to bet on long-term. Grails 8 is explicitly still in milestone/preview releases as of mid-2026, and the project's own...
25. How can you optimize GORM queries to avoid the N+1 problem?
Use eager fetching with join queries for associations you already know you'll need — a criteria query or HQL with an explicit join fetch retrieves the parent and its related records in a single database round trip instead of one query per parent, plus one more per child collection. Set the ...
26. How do you troubleshoot a LazyInitializationException in a Grails application?
This exception fires when code tries to access a lazily-loaded GORM association (a collection or a related object that wasn't eagerly fetched) after the database session/transaction that could have loaded it has already closed — a classic symptom of accessing persistence-backed data outside...
27. Explain the lifecycle of a request in a Grails application?
A request in Grails passes through several layers built on top of the underlying Spring Boot/servlet stack before a response is generated, with Grails' own conventions handling most of the routing and rendering decisions along the way. flowchart TD A[Incoming HTTP request] --> B[Servlet container...
28. Explain the execution flow of a GORM save() call under the hood?
Calling save() on a domain instance triggers a defined sequence of validation, event, and persistence steps before anything actually reaches the database, all coordinated by GORM's underlying datastore implementation (Hibernate, by default). sequenceDiagram participant Code as Application code pa...
29. Explain the internal working of GORM Data Services?
Unlike dynamic finders, which are resolved dynamically every time they're called at runtime, GORM Data Services do essentially all of their work once, at compile time , through a Groovy AST (Abstract Syntax Tree) transformation. flowchart TD A[Interface annotated with @grails.gorm.services.Servic...
30. What is the difference between an interceptor and a filter in Grails?
Both let code run before and after controller actions across many requests, but they represent two generations of the same idea — interceptors are the current, recommended mechanism, while filters are the older approach they largely replaced. Interceptor Filter (legacy) Defined as a Groovy ...
31. Why should you mark long-running database work with @Transactional at the service layer?
Grails services get transactional behavior automatically by convention, but understanding why that matters — and when to be explicit about it with @Transactional — comes down to guaranteeing that a group of related database operations either all succeed together or all roll back toget...
32. What is a Grails command object?
A command object is a plain Groovy class used to bind and validate incoming request data for a controller action, separate from any GORM domain class, which is useful whenever the shape of the data a form submits doesn't map cleanly onto a persisted entity. It gets its own constraints block just ...
33. How does Grails integrate with Spring Security?
Grails applications typically add authentication and authorization through the Spring Security plugin, which layers Grails' own conventions (domain classes, controllers, interceptors) on top of the underlying Spring Security framework rather than requiring a developer to configure Spring Security...
34. What is the difference between static and dynamic scaffolding in Grails?
Both generate a working CRUD interface from a domain class, but they differ in whether that generated code is written to disk as real, editable source files, or produced purely in memory at request time. Dynamic scaffolding Static (generated) scaffolding No files written to the project Real contr...
35. How does Grails support internationalization (i18n)?
Grails inherits Java's standard resource-bundle mechanism for i18n, storing translated text in .properties files under grails-app/i18n , with a base messages.properties file and locale-specific variants (like messages_fr.properties ) that Grails automatically selects based on the incoming request...
36. Explain the internal working of Grails' convention-based URL mapping?
Grails resolves an incoming URL against a prioritized set of mapping sources, checking explicit application-defined patterns before falling back to the generic controller/action convention, so both approaches can coexist in the same application. flowchart TD A[Incoming URL path] --> B[Load compil...
37. What is the difference between Grails profiles like "web" and "rest-api"?
A Grails profile determines the base project structure, default dependencies, and starting conventions a generated application uses — picking one when creating a project shapes what the initial skeleton looks like and which patterns feel like the default going forward. web profile rest-api ...
38. How do you enforce validation constraints on a Grails domain class?
Validation rules are declared in a domain class's static constraints closure, mapping each property to one or more constraint keywords, which GORM then automatically checks every time save() or validate() is called on an instance. Constraint What it enforces blank(false) Property cannot be an emp...
39. What is the role of the asset-pipeline plugin in Grails?
The asset-pipeline plugin manages an application's front-end assets — CSS, JavaScript, images — handling compilation, minification, bundling, and cache-busting so a developer doesn't have to wire up a separate front-end build tool just to get reasonably optimized static assets in prod...
40. How does Grails support database migrations?
Rather than relying purely on GORM's automatic schema generation (which is convenient for early development but risky for a production database with real data), Grails applications typically use the Database Migration plugin , built on Liquibase, to manage schema changes as explicit, version-cont...
41. 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 part...
42. What is the difference between GORM criteria queries and HQL?
Both let a developer express queries more powerful than dynamic finders, but they differ in syntax style and how strongly they're checked at compile time versus expressed as free-form text. Criteria queries HQL (Hibernate Query Language) Built programmatically with a Groovy closure/builder DSL Wr...
43. How do you configure multi-tenancy in a Grails application with GORM?
Choose a multi-tenancy strategy supported by GORM — common approaches include a separate database per tenant, a separate schema per tenant, or a shared table with a discriminator column identifying the tenant on every row. Mark domain classes as multi-tenant using GORM's multi-tenancy suppo...
44. What is the difference between Grails' component model and Spring Boot's plain REST controller approach?
Grails is built directly on Spring Boot, so the comparison isn't "Grails versus Spring Boot" as competing technologies — it's a question of how much of Grails' additional convention layer (GORM, GSP, scaffolding, plugin ecosystem) a project actually wants on top of the same underlying Sprin...
45. Explain how Grails' dependency injection works with Spring beans?
Grails doesn't build its own separate dependency injection container — it uses Spring's IoC container directly, and much of what looks like "Grails magic" for wiring services, beans, and configuration is really Grails automatically registering conventionally-named artifacts as Spring beans ...
46. How do you write unit and integration tests for a Grails application?
Use the standard Grails testing conventions , placing test classes in src/test/groovy mirroring the package structure of the code under test, built on top of Spock or JUnit depending on the project's chosen testing framework (Spock is the traditional Grails default, given its expressive, Groovy-n...
47. What is the difference between unit tests and integration tests in Grails testing?
Both verify application behavior, but they differ in scope, speed, and how much of the real Spring/GORM machinery is actually running behind the test. Unit test Integration test Tests one class in isolation, with dependencies mocked Tests multiple layers working together (controller + service + G...
48. Explain the internal working of a GORM dynamic finder at runtime?
Because a dynamic finder like findByTitleAndAuthor() never appears as real source code, GORM has to intercept the call at the moment it happens and figure out, from the method name string alone, what query the caller actually intended. flowchart TD A[Code calls Book.findByTitleAndAuthor(t, a)] --...
49. What is the difference between Apache Grails and Ruby on Rails?
Grails was directly inspired by Rails' productivity-focused philosophy, so the two share a great deal conceptually, but they run on different language runtimes and ecosystems, which shapes several practical differences beyond just syntax. Apache Grails Ruby on Rails Runs on the JVM, written in Gr...
50. Explain how GORM's optimistic locking prevents concurrent update conflicts?
Optimistic locking assumes conflicts are rare and checks for them only at save time, rather than locking a row the moment it's read (as pessimistic locking would) — GORM implements this automatically through the version property every domain class gets by default. sequenceDiagram participan...