-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

1

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.