Grails : Configuration
This page last changed on Mar 27, 2006 by [email protected].
ConfigurationConfiguring Start-upProgrammatic start-up configuration can be added a Grails application by creating one or many "BootStrap" classes in the "%PROJECT_HOME%\grails-app\conf" directory: ExampleBootStrap.groovy class ExampleBootStrap { @Property init = { servletContext -> // init app } @Property destroy = { // destroy app } } The "init" closure (if it exists) is called on application load and the "destroy" closure (again if it exists) on application exit
Configuring Data SourcesData source names should end with "DataSource". There are four required String properties:
class HsqlDataSource { @Property String dbCreate = "update" @Property String url = "jdbc:hsqldb:hsql://localhost" @Property String driverClassName = "org.hsqldb.jdbcDriver" @Property String username = "sa" @Property String password = "" } By default org.apache.commons.dbcp.BasicDataSource is used, all of its properties can be added to data source classes. If you want to disable connection pooling create a "pooling" property and set it to false. This will use org.springframework.jdbc.datasource.DriverManagerDataSource instead. Properties configured on Grails data sources that are not supported by DriverManagerDataSource will silently be ignored. @Property boolean pooling = false If no (available) data sources are found Grails will start with an in-memory HSQLDB database with the database schema created at run-time. By default Grails is configured to attempt to update or create the database on application load this is configured with the "dbCreate" property: @Property String dbCreate= "update" If this property is removed the database will have to be created manually or by a separate process. Other possible values for this property are "create" and "create-drop". Grails supports the scenario where multiple data sources are configured and data is modified through only one data source. This scenario does not require global transactions. To support this your must configure your DAO's to have dependencies injected by name instead of by type. Hibernate ConfigurationWhen Hibernate 3 is set as the persistence strategy all persistent domain classes are mapped in a Hibernate configuration file. Using other databasesGrails GORM is based on the Hibernate object/relational mapping framework. Therefore Hibernate is regularly tested with the following SQL databases:
Hibernate has also been tested with and is believed to be compatible with current versions of:
Using MySQLDownload the Java MySQL driver from: http://www.mysql.com/products/connector/j/ Unpack the archive and copy the mysql*.jar (not the debug jar) to lib Change the ApplicationDataSource to using your own values: class ApplicationDataSource { @Property boolean pooled = true @Property String dbCreate = "create-drop" @Property String url = "jdbc:mysql://localhost/yourDB" @Property String driverClassName = "com.mysql.jdbc.Driver" @Property String username = "yourUser" @Property String password = "yourPassword" } DebuggingDebugging HibernateTo log all SQL queries and all the stuff hibernate does, add the line log4j.logger.org.hibernate=debug, stdout To the log4j.properties file in: tmp/war/WEB-INF |
![]() |
Document generated by Confluence on Mar 29, 2006 08:46 |