VOOZH about

URL: https://www.javacodegeeks.com/2016/02/grails-3-datasource-configuration.html

⇱ Grails 3 DataSource Configuration - Java Code Geeks


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.
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Thank you!

We will contact you soon.

Tags
Grails
👁 Photo of Todd McGrath
Todd McGrath
February 22nd, 2016Last Updated: February 21st, 2016
0 213 1 minute read

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

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

0 Comments
Oldest
Newest Most Voted
Back to top button
Close
wpDiscuz