Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Grails dataSource in resources.groovy?

I have an external java library I am using in my Grails project. It needs a DataSource via the Spring configuration. However, the dataSource appears to not be accessible from resources.groovy. How do I get access to it? I'm using the following in resources.groovy:

beans = {
 eventDao(com.JavaClassRequiringDataSource) {
  //dataSource = ref(dataSource, true)
  dataSource = dataSource
 }
}

Running the app results in a exception:

org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingPropertyException: No such property: dataSource for class: grails.spring.BeanBuilder

Any ideas?

like image 643
Mike Avatar asked Feb 08 '10 14:02

Mike


People also ask

Is Groovy and Grails are same?

Grails is an open source web application framework that uses the Apache Groovy programming language (which is in turn based on the Java platform).

Does grails come with Groovy?

Grails is a Java-based web application framework that uses the Apache Groovy programming language.

Is Grails a good framework?

Grails is superb because it allows developers to concentrate more on actual application requirements and spend less time configuring the framework. Grails provide tools for development, and it is built based on tools like: Quarts, Hibernate, Spring, and Gradle for library management.


1 Answers

According to http://www.grails.org/Spring+Bean+Builder your method should be right.. I just did some Googleing and found that this should do it (untested):

beans = {
 eventDao(com.JavaClassRequiringDataSource) {
  dataSource = ref('dataSource', true)
 }
}

so you do not reference it by variable, but by name. (Source: http://burtbeckwith.com/blog/?cat=23)

like image 82
sbglasius Avatar answered Sep 20 '22 04:09

sbglasius