Is it possible to use .properties files in web.xml in conjunction with contextConfigLocation parameter?

前端 未结 2 737
陌清茗
陌清茗 2021-02-04 22:08

Here is part of my web.xml:


        contextConfigLocation
        
            clas         


        
相关标签:
2条回答
  • 2021-02-04 22:31

    Totally agree with axtavt. So all the info combined the most simple solution with Spring 3.0 thus is:

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

    with

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

    in web.xml.

    0 讨论(0)
  • 2021-02-04 22:33

    Yes, you can use ServletContextParameterFactoryBean to expose context-param value (it also requires full form of PropertyPlaceholderConfigurer instead of simple context:property-placeholder):

    <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>
    

    Or use Spring 3.0's EL:

    <bean class = 
        "org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value = "#{contextParameters.myParameter}" />
    </bean>
    
    0 讨论(0)
提交回复
热议问题