在我们的应用程序中,我们有两个hibernate事件监听器。一个用于审计日志记录,另一个用于Solr服务器中的索引。
但是我们面临的问题是现在只有一个被调用。 请在下面找到配置详细信息:
代码段
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
答案 0 :(得分:2)
我的不好,我没有正确注册听众: 添加了以下代码段:
['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
}