Created
November 22, 2016 14:04
-
-
Save kdabir/b32b2d2e7ce92ca8597fd06f285945b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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