Skip to content

Instantly share code, notes, and snippets.

@kdabir
Created November 22, 2016 14:04
Show Gist options
  • Save kdabir/b32b2d2e7ce92ca8597fd06f285945b3 to your computer and use it in GitHub Desktop.
Save kdabir/b32b2d2e7ce92ca8597fd06f285945b3 to your computer and use it in GitHub Desktop.
class Servlet {
String name, fqcn
List patterns = []
def getPatternsStr() {
patterns.collect { /"$it"/ }.join(", ")
}
}
def web = new XmlSlurper().parse(new File('webapp/WEB-INF/web.xml'))
def servlets = web.servlet.collectEntries { [it.'servlet-name'.text(), new Servlet(name: it.'servlet-name'.text(), fqcn: it.'servlet-class'.text())] }
web.'servlet-mapping'.each {
servlets[ it.'servlet-name'.text()].patterns.addAll(it.'url-pattern'.collect{it.text()})
}
servlets.collect { k,s ->
"""
@Bean
public ServletRegistrationBean get${s.name}(){
return new ServletRegistrationBean(new ${s.fqcn}(), ${s.patternsStr});
}
"""
}.join("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment