Ist es möglich zu verwenden .Eigenschaften Dateien in web.xml in Verbindung mit parameter contextConfigLocation?

StackOverflow https://stackoverflow.com/questions/2515954

  •  22-09-2019
  •  | 
  •  

Frage

Hier ist ein Teil meines web.xml:

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

application-config.xml nutzt die Eigenschaft Platzhalter:

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

Ist es irgendwie möglich zu definieren, welche Eigenschaften Datei in web.xml anstatt in application-config.xml?

War es hilfreich?

Lösung

Ja, Sie können ServletContextParameterFactoryBean aussetzen context-param Wert (es erfordert auch die volle form von PropertyPlaceholderConfigurer statt der einfachen 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>

Oder verwenden Sie Spring 3.0-EL:

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

Andere Tipps

Völlig einverstanden mit axtavt.So alle Infos kombiniert die einfache Lösung mit Spring 3.0 ist somit:

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

mit

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

in web.xml.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top