Datasource defined in resources.groovy is null is Grails services

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Datasource defined in resources.groovy is null is Grails services

Shweta Nivargi
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

 

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/8134bb34-1c74-4e88-8a69-7d6a6e0faa87%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...