-1

I need to get context-param values from a web.xml to override values in a resources.groovy. The Grails documentation purpose just to use a placeholder with a property file but the solution is not appropriate because in the future I want to use deployment plan with weblogic to override the context-param for different environnement. It's impossible to use ServletContextPropertyPlaceholderConfigurer because is deprecated now. Have you a solution ?

Thank you

Padapiou
  • 1
  • 2
  • I'm not sure about the groovey stuff, but you could still use a property-placeholder: http://stackoverflow.com/a/21175824/1669464 – Pytry Jan 17 '14 at 23:34

1 Answers1

0

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

Padapiou
  • 1
  • 2