Groovy

Grails 3 DataSource Configuration

Grails 3 has new configuration files and format.  The new format is based on YAML and the file name to use for database configuration is grails-app/conf/application.yml.   I’m just getting started with Grails 3 after developing applications on Grails pre-1, 1 and 2.  I was looking forward to building a new Grails 3 application.

Before I began, I read the Grails 2 to Grails 3 upgrade notes and was feeling pretty confident.  But, I ran into an issue yesterday which I thought I’d describe here in case it helps you.

First, here’s a working snippet of application.yml which a data source configured for mySQL

dataSource:
    pooled: true
    jmxExport: true
    # driverClassName: org.h2.Driver
    driverClassName: com.mysql.jdbc.Driver
    # dialect: org.hibernate.dialect.MySQL5InnoDBDialect
    username: root
    password: root
 
environments:
    development:
        dataSource:
            # dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
            dbCreate: create
            url: jdbc:mysql://localhost/demo?autoReconnect=true

But, here’s where you should be careful.

Make sure you are not using the old format of <variable_name> = “<setting>” in YAML files.  What do I mean?  Well, here’s an example:

dataSource:
    pooled: true
    jmxExport: true
    # driverClassName: org.h2.Driver
    driverClassName: com.mysql.jdbc.Driver
    # dialect: org.hibernate.dialect.MySQL5InnoDBDialect
    username: root
    password: root
 
environments:
    development:
        dataSource:
            # dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
            dbCreate = "create"
            url = "jdbc:mysql://localhost/demo?autoReconnect=true"

I had the Grails 3 Data Source configuration this way and was receiving errors on grails run-app startup:

ERROR org.springframework.boot.SpringApplication - Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'persistenceInterceptor': Cannot resolve reference to bean 'hibernateDatastore' while setting bean property 'hibernateDatastore'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'hibernateDatastore' is defined

Yes, in retrospect, this is embarrassing.  I spent more time debugging this than I care to admit.  So, just in case it helps anyone out there, I’m writing this down for you.

Reference: Grails 3 DataSource Configuration from our JCG partner Todd McGrath at the Supergloo blog.

Todd McGrath

Todd is a consultant in data engineering and software development using Scala, Apache Spark, Scala, Groovy, Python, relational, columnar and noSQL databases. He is a 20-year software veteran and founder of supergloo, inc.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button