开发者

How to obtain handle to Grails datasource

开发者 https://www.devze.com 2022-12-20 15:15 出处:网络
I want a handle to connection object in grails controller class (written in groovy). I read somewhere that I need to first obtain datasource object and call a method getConnection on it to get the con

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

I am unable to find how to obtain the datasource object in开发者_开发知识库 grails controller. Kindly help.


The datasource is simply a bean. It can be injected by Spring into pretty much anything.

    def dataSource

But I would recommend that you inject the dataSource into a Service, do your getConnection call there and whatever work you need done. I think that's a better separation of responsibilities.

Then inject your service into your controller and call it.

0

精彩评论

暂无评论...
验证码 换一张
取 消