我的插件的定义文件中包含以下代码:
def doWithWebDescriptor = { xml ->
// Implement additions to web.xml (optional), this event occurs before
xml.'welcome-file-list'[0] + {
'security-constraint'({
'web-resource-collection'({
'web-resource-name'('Java Melody Monitoring')
'url-pattern'('/monitoring')
})
'auth-constraint'({
'role-name'('melody')
})
})
'login-config'({
'auth-method'('BASIC')
'realm-name'('Restricted Area')
})
}
}
这会将“security-constraint”和“login-config”节点添加到web.xml文件中,但是,我目前已对其进行了硬编码,以在“welcome-file-list”节点之后添加。我不知道的是如何简单地告诉它将这些节点添加为“web-app”根节点中的最后一个节点。
最佳答案
捕获 child ,在最后一个 child 之后追加。
xml.children()[-1] + {
'security-constraint'({
'web-resource-collection'({
'web-resource-name'('Java Melody Monitoring')
'url-pattern'('/monitoring')
})
'auth-constraint'({
'role-name'('melody')
})
})
'login-config'({
'auth-method'('BASIC')
'realm-name'('Restricted Area')
})
}
关于xml - Grails:将XML节点添加为插件的doWithWebDescriptor中的最后一个web.xml节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23348374/