4.2.2 Customizing the Application Class - Reference Documentation
Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith, Lari Hotari
Version: 3.1.6
4.2.2 Customizing the Application Class
There are several ways in which you can customize theApplication
class.Customizing Scanning
By default Grails will scan all known source directories for controllers, domain class etc., however if there are packages in other JAR files you wish to scan you can do so by overriding thepackageNames()
method of the Application
class:class Application extends GrailsAutoConfiguration { @Override Collection<String> packageNames() { super.packageNames() + ['my.additional.package'] } … }
Registering Additional Beans
TheApplication
class can also be used as a source for Spring bean definitions, simply define a method annotated with the Bean and the returned object will become a Spring bean. The name of the method is used as the bean name:class Application extends GrailsAutoConfiguration { @Bean MyType myBean() { return new MyType() } … }