How to get a handle for a Grails data source

I need a handle to the connection object in the grails controller class (written in groovy). I read somewhere that I need to get the datasource object first and call the getConnection method on it to get the connection object.

I cannot find how to get datasource object in grails controller. Please help.

+4
source share
1 answer

The data source is just a bean. It can be entered by Spring in almost anything.

def dataSource 

But I would recommend that you insert the data source into the service, make a call to getConnection and any work that you need. I believe the best separation of duties.

Then enter your service in your controller and call it.

+9
source

Source: https://habr.com/ru/post/1301527/


All Articles