2010-03-25 1 views
3

내 web.xml 파일의 일부입니다web.xml에서 contextConfigLocation 매개 변수와 함께 .properties 파일을 사용할 수 있습니까? 여기

<context:property-placeholder location="classpath:properties/db.properties"/> 

는 특성이 오히려 web.xml 파일에서 사용하는 파일을 정의 할 어떻게 든 가능 :

<context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value> 
      classpath:application-config.xml 
     </param-value> 
</context-param> 

응용 프로그램-config.xml의 속성 자리 표시자를 사용 application-config.xml보다? 스프링 3.0의 EL

<bean id = "myLocation" class = 
    "org.springframework.web.context.support.ServletContextParameterFactoryBean"> 
    <property name="initParamName" value = "myParameter" /> 
</bean> 

<bean class = 
    "org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
    <property name="location" ref = "myLocation" /> 
</bean> 

또는 사용 :

+0

web.xml에서 db.properties를 어떻게 가져 왔습니까? 나는 $ {property.name}을 시도했다. 그러나 그것은 작동하지 않습니다. – Ani

답변

4

예, context-param 값을 표시하는 ServletContextParameterFactoryBean을 사용할 수 있습니다 (이것은 또한 PropertyPlaceholderConfigurer의 전체 형태 대신 간단한 context:property-placeholder 필요)

<bean class = 
    "org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
    <property name="location" value = "#{contextParameters.myParameter}" /> 
</bean> 
+6

여러분이이 답변을 명확히 할 수 있다면 많은 사람들에게 도움이 될 것이라고 확신합니다. – euther

4

Axtavt와 완전히 동의합니다. 그래서 모든 정보 따라서 봄 3.0 가장 간단한 솔루션을 결합이다 :

<context:property-placeholder location="#{contextParameters.propertiesLocation}"/> 

web.xml에

<context-param> 
    <param-name>propertiesLocation</param-name> 
    <param-value>classpath:properties/db.properties</param-value> 
</context-param> 

와 함께.

+0

이렇게하면 db.properties 파일의 속성을 읽고 applicationContext.xml과 web.xml에서 '$ {yaddayadda}'를 사용하여이 속성을 사용할 수 있습니다. –

+1

@Oliver : 위에 언급 한대로 web.xml에서 읽고 web.xml에서 지정한 컨텍스트 매개 변수와 app.xml의 context-property를 읽어야하는 config.properties가 있습니다. $ {SystemInfo}을 web.xml에 표시하지만 $ {SystemInfo}를 표시하는 값을 표시하지 않습니다 .. –

+0

안녕하세요. 이 기능을 작동시키는 데 필요한 다른 것이 있습니까? 이렇게하면 ServletContext 리소스 [/ # {contextParameters.propertiesLocation}]를 열 수 없습니다. – thedarklord47

관련 문제