스프링 컨텍스트 XML 파일에서 servletContext 사전 정의 변수가 null인지 아닌지에 따라 스프링 EL 표현식을 사용하여 속성 파일을 다르게로드합니다.Spring 표현식 languague - servletContext 변수가 정의되어 있는지 확인
#{
systemProperties['my.properties.dir'] != null ?
'file:' + systemProperties['my.properties.dir'] + '/' :
(servletContext != null ?
'file:/apps/mydir' + servletContext.getContextPath() + '/' :
'classpath:')
}my.properties
내가 웹 응용 프로그램에서 실행하면, 모든 것이 괜찮 : 아래 (읽기 쉽도록 포맷)을 게임 드라이버 표현이다. 내가 독립 실행 형 응용 프로그램으로 실행할 때, (ServletContext를 미리 정의 된 변수를 의미하는 정의되지 않은), 나는 다음과 같은 오류가 발생합니다 :
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 109): Field or property 'servletContext' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext'
의 servletContext가 존재하는지 확인하는 방법이 있나요? 아니면 정의되지 않은 예외를 피하기 위해 어떤 방법?