xml - Grails:将XML节点添加为插件的doWithWebDescriptor中的最后一个web.xml节点

标签 xml grails nodes web.xml

我的插件的定义文件中包含以下代码:

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/

相关文章:

c# - 无法将 json 转换为 xml

xml - 如何使用 Xpath 匹配一个或另一个元素

xml - dbms_xmlgen.getxml - 如何设置日期格式

grails - GORM-表的层次结构-如何在域类中更改表名

grails - Grails从1.3.7升级到3.2.6的路径

javascript - Grails 3.0 <g :remoteLink . ..> 由于弃用而替换 Ajax 调用

javascript - 如何在 javascript 中使用 map 函数而不是 for 循环?

xml - 使用 XML 声明自定义 android UI 元素

c - 插入AVL树的函数不会插入

c++ - 带节点删除函数的链表问题