API / Apache Grails Interview questions
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 name ends in Service is automatically registered as a Spring bean and, by default, wrapped in a database transaction for every public method — if an exception propagates out of a service method, GORM changes made during that method roll back automatically, without the developer writing explicit transaction-management code. Controllers typically obtain a service through Grails' dependency injection simply by declaring a field of the service's type; no manual wiring is required.
Keeping business logic in services rather than controllers or views also makes it far easier to unit test in isolation — a service can be instantiated and exercised directly in a test without needing an HTTP request or a rendered view in the loop at all.
More Related questions...