2013-11-15 24 views
-1

我需要從web.xml中獲取context-param值來覆蓋resources.groovy中的值。 Grails文檔的目的只是爲了使用佔位符與屬性文件,但該解決方案並不合適,因爲將來我希望使用帶有weblogic的部署計劃來覆蓋不同環境的上下文參數。使用ServletContextPropertyPlaceholderConfigurer是不可能的,因爲現在已經被棄用了。你有解決方案嗎?如何讀取resources.groovy中的context-param(web.xml)值grails 2.3

謝謝

+0

我不知道的東西groovey,但你仍然可以使用屬性佔位符:http://stackoverflow.com/a/21175824/1669464 – Pytry

回答

0

首先,加webXml插件安裝到你的Grails項目。這個插件增加了在戰爭中生成web.xml之後添加context-param的可能性。 創建您-APP /的grails-app/conf目錄/ WebXmlConfig.groovy,並覆蓋:

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 
} 

,在你resources.groovy,您可以使用org.codehaus.groovy.grails.web.context。 ServletContextHolder.getServletContext()

我看到這裏的解決方案:accessing-servletContext-in-resources-groovy

你打電話的getInitParameter方法來獲取在web.xml中聲明價值。

beans = { 

ServletContext sc= org.codehaus.groovy.grails.web.context.ServletContextHolder.getServletContext() 
String value = sc.getInitParameter('sample') 

} 

它可以幫助你

相關問題