Firstly, add webXml plugin into your Grails Project. This plugin add possibility to add context-param after the web.xml generation in the war.
create YOUR-APP/grails-app/conf/WebXmlConfig.groovy, and override :
webxml {
filterChainProxyDelegator.add = false
filterChainProxyDelegator.targetBeanName = "filterChainProxyDelegate"
filterChainProxyDelegator.urlPattern = "/*"
filterChainProxyDelegator.filterName = "filterChainProxyDelegator"
filterChainProxyDelegator.className = "org.springframework.web.filter.DelegatingFilterProxy"
listener.add = false
//listener.classNames = ["org.springframework.web.context.request.RequestContextListener"]
contextparams = [sample: 'Sample Value'] // Add your context param
// sessionConfig.sessionTimeout = 30
}
after that, in your resources.groovy, you can use org.codehaus.groovy.grails.web.context.ServletContextHolder.getServletContext()
I saw the solution here: accessing-servletContext-in-resources-groovy
You call getInitParameter method to get values declared in the web.xml.
beans = {
ServletContext sc= org.codehaus.groovy.grails.web.context.ServletContextHolder.getServletContext()
String value = sc.getInitParameter('sample')
}
It can help you