我想自动设置我的DomainClasses的modifiedBy和createdBy属性。 为此,我将Bootstrap.grooy更改为:
__strong typeof(weakSelf) strongSelf = weakSelf;
要完成这项工作,我需要在所有具有属性的DomainClasses中使用springSecurityService,我可以添加:
import org.codehaus.groovy.grails.commons.GrailsDomainClass
class BootStrap {
def grailsApplication
def init = { servletContext ->
grailsApplication.domainClasses.each { GrailsDomainClass gdc ->
if (gdc.hasProperty('modifiedBy') && gdc.hasProperty('createdBy')) {
gdc.metaClass.beforeInsert = {
modifiedBy = springSecurityService.currentUser.id
createdBy = springSecurityService.currentUser.id
}
}
if (gdc.hasProperty('modifiedBy') && gdc.hasProperty('modified')) {
gdc.metaClass.beforeUpdate = {
modified = new Date()
modifiedBy = springSecurityService.currentUser.id
}
}
}
}
}
如何在没有它的情况下注入springSecurityService?