Skip to content

Commit

Permalink
Allow disabling of Spring proxy-based transaction management
Browse files Browse the repository at this point in the history
As per #9272 Grails no longer needs proxy-based transaction management
since the `@Transactional` transform already handles this. For
backwards compatibility we still enable proxy based transaction
management, but it is disabled by default for new applications.
  • Loading branch information
graemerocher committed Dec 9, 2015
1 parent c9a25fe commit 623d575
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 6 additions & 0 deletions grails-core/src/main/groovy/grails/config/Settings.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ interface Settings {
*/
String SPRING_PLACEHOLDER_PREFIX = "grails.spring.placeholder.prefix";

/**
* Whether to enable Spring proxy based transaction management. Since {@link grails.transaction.Transactional} uses an AST transform, this makes Spring proxy based transaction management redundant.
* However, if Spring proxies are prefer
*/
String SPRING_TRANSACTION_MANAGEMENT = "grails.spring.transactionManagement";

/**
* Which plugins to include in the plugin manager
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.grails.plugins.services

import grails.config.Config
import grails.config.Settings
import grails.plugins.Plugin
import grails.util.GrailsUtil
import groovy.transform.CompileStatic
Expand Down Expand Up @@ -49,12 +50,16 @@ class ServicesGrailsPlugin extends Plugin {
"file:./plugins/*/grails-app/services/**/*Service.groovy"]

Closure doWithSpring() {{->
xmlns tx:"http://www.springframework.org/schema/tx"
tx.'annotation-driven'('transaction-manager':'transactionManager')

def application = grailsApplication
Config config = application.config

final boolean springTransactionManagement = config.getProperty(Settings.SPRING_TRANSACTION_MANAGEMENT, Boolean.class, true)

if(springTransactionManagement) {
xmlns tx:"http://www.springframework.org/schema/tx"
tx.'annotation-driven'('transaction-manager':'transactionManager')
}

for (GrailsServiceClass serviceClass in application.serviceClasses) {
def providingPlugin = manager?.getPluginForClass(serviceClass.clazz)

Expand All @@ -76,7 +81,7 @@ class ServicesGrailsPlugin extends Plugin {


def hasDataSource = (config?.dataSources || application.domainClasses)
if (hasDataSource && shouldCreateTransactionalProxy(serviceClass)) {
if (springTransactionManagement && hasDataSource && shouldCreateTransactionalProxy(serviceClass)) {
def props = new Properties()

String attributes = 'PROPAGATION_REQUIRED'
Expand Down Expand Up @@ -148,10 +153,12 @@ class ServicesGrailsPlugin extends Plugin {
def serviceName = "${serviceClass.propertyName}"
def scope = serviceClass.getPropertyValue("scope")

final boolean springTransactionManagement = config.getProperty(Settings.SPRING_TRANSACTION_MANAGEMENT, Boolean.class, true)

String datasourceName = serviceClass.datasource
String suffix = datasourceName == GrailsServiceClass.DEFAULT_DATA_SOURCE ? '' : "_$datasourceName"

if (shouldCreateTransactionalProxy(serviceClass) && ctx.containsBean("transactionManager$suffix")) {
if (springTransactionManagement && shouldCreateTransactionalProxy(serviceClass) && ctx.containsBean("transactionManager$suffix")) {

def props = new Properties()
String attributes = 'PROPAGATION_REQUIRED'
Expand Down

0 comments on commit 623d575

Please sign in to comment.