Spring application context : access web.xml context-params?

后端 未结 1 1110
孤独总比滥情好
孤独总比滥情好 2020-12-03 05:45

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 :

&l         


        
相关标签:
1条回答
  • 2020-12-03 05:58

    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}")

    0 讨论(0)
提交回复
热议问题