سؤال

تحية طيبة ،

هل هناك أي طريقة للحصول على قيم من web.xml السياق في سياق الربيع؟

على سبيل المثال ، أقوم بتحديد القيمة في web.xml على النحو التالي:

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

وأريد تعيين هذه القيمة لممتلك الفول على النحو التالي:

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

شكرا لك مقدما؟

هل كانت مفيدة؟

المحلول

نعم - ServletContextPropertyPlaceholderConfigurer

هذه المقالة يشرح التفاصيل. باختصار ، تحتاج:

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

ثم استخدم الخصائص مثل:

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

أو مع @Value("${compass-index}")

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top