Datasource defined in resources.groovy is null is Grails services

141 views
Skip to first unread message

Shweta Nivargi

unread,
Aug 25, 2016, 8:52:56 AM8/25/16
to Grails Dev Discuss
Hi,

I am trying to upgrade my grails application from version 2.0 to 2.5.4
Facing issue that the jdbcTemplate bean defined in resources.groovy is null in Grails services. The same thing worked fine in earlier version of grails (tried versions 1.3.3 and 2.0).
Are there any changes in Grails version 2.5 related to autowiring of beans ?

resouces.groovy

import org.springframework.jdbc.core.JdbcTemplate
...
jdbcTemplate(JdbcTemplate) {
   dataSource = ref('dataSource')
...
}

DataSource.groovy
dataSource {
    configClass = GrailsAnnotationConfiguration.class
    pooled = true
    autoreconnect= true 
}

hibernate {
    generate_statistics=true
    cache.use_second_level_cache=true
    cache.use_query_cache=true
    cache.region.factory_class = 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory' 

}


environments {
   development {
      dataSource {
         driverClassName = "com.mysql.jdbc.Driver"
         username = "test"
         password = "test"
         dbCreate = "update" // one of 'create', 'create-drop','update'
         pooled = true
         jmxExport = true
         url = "jdbc:mysql://host:port/dbName?autoReconnect=true"
    }
}
}

Service class

def jdbcTemplate

def someMethod(){
    jdbcTemplate.queryForList(somequery) 
}
Exception: Cannot invoke method queryForList() on null object. Stacktrace follows: Message: Cannot invoke method queryForList() on null object

Any help is appreciated.
Thanks
Shweta

Question posted on stackoverflow - 
http://stackoverflow.com/questions/39120000/grails-app-upgrade-2-5-datasource-is-null

 
Reply all
Reply to author
Forward
0 new messages