Stop Grails from opening a database connection in the controller method

I have a service that communicates with another machine. Since this is a simple controller method, Grails automatically grabs the DB connection from the pool, and my controller communicates with another server. I would like to prevent this and manually open the database connection when I am ready so that it does not retract the connection for a long period of time, like making network calls. How to prevent Grails from automatically capturing a connection from the pool in the controller method?

+6
source share
1 answer

When you create a controller, it has a Transactional annotation on it, for example:

  @Transactional(readOnly=true) class FooController { .. 

If you delete the annotation (and annotations of any level), Grails will no longer connect to the database to start the transaction.

Open an In View session should not enter the game, since we use the lazy init approach to get a connection to OSIV

Please note that my answer above assumes you are using the latest version of Grails (2.3.x or higher)

Updated

For MongoDB, you can disable automatic connection for all controllers by specifying the following bean (which overrides the default value) in grails-app/conf/spring/resources.groovy :

  mongoPersistenceInterceptor(org.codehaus.groovy.grails.support.NullPersistentCon‌​textInterceptor) 

However, at the moment there is no way to disable based on each controller

+3
source

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


All Articles