2012-10-10 3 views
0

나는 grails에서 일부 사용자 정의 속성을 외부화하려고합니다.grails 속성을 외부화

일부 문자열 속성을 외부화하고 내 코드에서 사용하는 방법에 대한 명확한 방법을 찾을 수 없습니다. 누구든 도와주세요.

+3

http://grails.org/doc/latest/guide/conf.html#configExternalized를 읽었습니까? –

답변

1

config.groovy에서 외부 구성 파일의 위치를 ​​지정해야합니다. 이 같은 예를 들어

:

if (!grails.config.locations || !(grails.config.locations instanceof List)) { 
    grails.config.locations = [] 
} 

// Internal Jetty: config-files are locates inside the /web-app/WEB-INF directory 
if(GrailsUtil.isDevelopmentEnv()) { 
    def dir = System.properties["base.dir"] 
    def f1 = "${dir}" + File.separator + "web-app" + File.separator + "WEB-INF" + File.separator + "${appName}-config.groovy" 
    grails.config.locations << "file:${f1}" 
} 

// TIER Tomcat: config-files are locates inside Tomcat's conf-directory 
else if(System.properties["catalina.home"]) { 
    def dir = System.properties["catalina.home"] 
    def f1 = "${dir}" + File.separator + "conf" + File.separator + "${appName}-config.groovy" 
    grails.config.locations << "file:${f1}" 
} 

// JBOSS, Glassfish etc 
else { 
    // 
} 

// Further choices: command line argument (-D{$appName}.config.location=xxx) 
if(System.properties["${appName}.config.location"]) { 
    grails.config.locations << "file:" + System.properties["${appName}.config.location"] 
} 

그래서 지역 발전에 설정 파일은 WEB-INF 디렉토리에 위치합니다. 인생을 살아가는 동안 구성 파일을 저장할 위치를 다양하게 선택할 수 있습니다. 필요한 경우 동일한 방법으로 config.properties에서 작동하도록 코드를 조정할 수 있습니다.

관련 문제