문제

Greetings ,

Is there any way to get values from web.xml context-param into Spring context?

For example I define the value in web.xml as :

<context-param>
  <param-name>compass-index</param-name>
  <param-value>file:///home/compass/index</param-value>
</context-param>

And I want to assign that value to the bean-property as:

<bean ...>
<props>
  <prop key="compass.engine.connection">
    ${from web.xml context-param?}
  </prop>
</props>
</bean>

Thanks in advance?

도움이 되었습니까?

해결책

Yes - ServletContextPropertyPlaceholderConfigurer

This article explains the details. In short, you need:

<bean class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer">
</bean>

and then use the properties like:

<bean ...>
   <property name="compassIndex" value="${compass-index}" />
</bean>

or with @Value("${compass-index}")

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top