在resources.groovy中注册了多个Hibernate事件侦听器
在我们的应用程序中,我们有两个hibernate事件监听器。一个用于审计日志记录,另一个用于在Solr服务器中建立索引 但是,我们目前面临的问题是,到目前为止,只有一个问题被称为。 请查看以下配置详细信息:在resources.groovy中注册了多个Hibernate事件侦听器,hibernate,grails,Hibernate,Grails,在我们的应用程序中,我们有两个hibernate事件监听器。一个用于审计日志记录,另一个用于在Solr服务器中建立索引 但是,我们目前面临的问题是,到目前为止,只有一个问题被称为。 请查看以下配置详细信息: 代码片段 A] Inside AuditLoggingProjPlugin.groovy: def loadAfter = ['core','hibernate'] def doWithSpring = { if (manager?.hasGrail
代码片段
A] Inside AuditLoggingProjPlugin.groovy:
def loadAfter = ['core','hibernate']
def doWithSpring = {
if (manager?.hasGrailsPlugin("hibernate")) {
auditLogListener(AuditLogListener) {
grailsApplication = ref('grailsApplication')
sessionFactory = sessionFactory
verbose = application.config?.auditLog?.verbose?:false
transactional = application.config?.auditLog?.transactional?:false
sessionAttribute = application.config?.auditLog?.sessionAttribute?:""
actorKey = application.config?.auditLog?.actorKey?:""
logIds = application.config?.auditLog?.logIds?:false
replacementPatterns = application.config?.auditLog?.replacementPatterns?:null
propertyMask = application.config?.auditLog?.propertyMask?:""
}
}
}
def doWithApplicationContext = { applicationContext ->
// pulls in the bean to inject and init
AuditLogListener listener = applicationContext.getBean("auditLogListener")
// allows to configure the Actor name Closure in the config
listener.setActorClosure(application.config?.auditLog?.actorClosure?:AuditLogListenerUtil.actorDefaultGetter )
listener.init()
// allows user to over-ride the maximum length the value stored by the audit logger.
if(application.config?.auditLog?.TRUNCATE_LENGTH) {
listener.truncateLength = new Long(application.config?.auditLog?.TRUNCATE_LENGTH)
}
}
B] Inside SolrIndexProjPlugin.groovy:
def doWithSpring = {
// TODO Implement runtime spring config (optional)
if (manager?.hasGrailsPlugin("hibernate")) {
searchPersistenceListener(SearchPersistenceListener) {
solrIndexService = ref("solrIndexService")
}
}
//start of search indexing listener
//this might need to be commented out if other plugins are not up to date
/* searchPersistenceListener(com.xms.core.search.SearchPersistenceListener){
solrIndexService = ref("solrIndexService")
}
hibernateEventListeners(org.codehaus.groovy.grails.orm.hibernate.HibernateEventListeners) {
listenerMap = ['post-commit-insert': searchPersistenceListener,
'post-commit-update': searchPersistenceListener,
'post-commit-delete': searchPersistenceListener]
}*/
//end of search indexing listener
}
def doWithDynamicMethods = { ctx ->
// TODO Implement registering dynamic methods to classes (optional)
}
def doWithApplicationContext = { applicationContext ->
// TODO Implement post initialization spring config (optional)
def listeners = applicationContext.sessionFactory.eventListeners
SearchPersistenceListener listener = applicationContext.getBean("searchPersistenceListener")
['postCommitInsert', 'postCommitUpdate', 'postCommitDelete'].each({
addEventTypeListener(listeners, listener, it)
})
}
def addEventTypeListener(listeners, listener, type) {
def typeProperty = "${type}EventListeners"
def typeListeners = listeners."${typeProperty}"
def expandedTypeListeners = new Object[typeListeners.length + 1]
System.arraycopy(typeListeners, 0, expandedTypeListeners, 0, typeListeners.length)
expandedTypeListeners[-1] = listener
listeners."${typeProperty}" = expandedTypeListeners
}
我强烈地认为我在项目插件的配置中遗漏了一些东西,而这些东西完全丢失了
强烈要求帮助
注意,MB我的错,我没有正确注册侦听器: 添加以下代码段:
['postCommitInsert','postCommitUpdate', 'postCommitDelete'].each({
addEventTypeListener(listeners, listener, it)
})
}
def addEventTypeListener(listeners, listener, type) {
def typeProperty = "${type}EventListeners"
def typeListeners = listeners."${typeProperty}"
def expandedTypeListeners = new Object[typeListeners.length + 1]
System.arraycopy(typeListeners, 0, expandedTypeListeners, 0, typeListeners.length)
expandedTypeListeners[-1] = listener
listeners."${typeProperty}" = expandedTypeListeners
}