환영합니다. 그러나 ConfigSlurper
은 표준 Java 등록 정보 파일을 지원하지 않습니다. 일반적으로 ConfigSlurper
은 속성 파일과 유사한 .groovy 파일을 읽는 데 사용되지만 표준 그루비 표기법을 따르므로 문자열은 따옴표 안에 있고 주석은 //
으로 시작하거나 /* */
블록 안에 있습니다. 따라서, Java 특성 당신이 java.util.Properties
객체를 생성하고 생성하는 것을 사용할 필요가 파일을 읽을 수있는 ConfigSlurper
: 만 그루비 코드 내에서 프로퍼티 파일을 사용하는 경우
def props = new Properties()
new File("message.properties").withInputStream {
stream -> props.load(stream)
}
// accessing the property from Properties object using Groovy's map notation
println "capacity.created=" + props["capacity.created"]
def config = new ConfigSlurper().parse(props)
// accessing the property from ConfigSlurper object using GPath expression
println "capacity.created=" + config.capacity.created
는 그루비 표기 변형을 직접 사용해야합니다.
def config = new ConfigSlurper().parse(new File("message.groovy").toURL())
이렇게하면 표준 속성 파일에 비해 몇 가지 장점이 있습니다. 내가 직접 모든 메시지 특성 파일 (message_de.properties, message_fr.properties 등을 다시 읽는 wothout 메시지 속성에 액세스하는 방법을 발견
capacity {
created="x"
modified="y"
}
나는 컨트롤러가 아닌 별도의 클래스를 가지고 있는데, 시도해 보았는데 작동하지 않는다 ... 어떤 제안이라도 있니? –
@ CPU100 그 클래스에'messageSource'를 삽입하고' –
이것은 제목에 동적 값을 전달해야하는 곳에서 효과가있었습니다. –
Xplora