それはcontextConfigLocationパラメーターと一緒にweb.xmlに.propertiesファイルを使用することは可能ですか?

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

  •  22-09-2019
  •  | 
  •  

質問

ここに私のweb.xmlの一部であります:

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

アプリケーション-config.xmlを使用プロパティプレースホルダ

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

これはどういうわけか、web.xmlではなく、アプリケーション-config.xmlに使用するプロパティファイルを定義することは可能ですか?

役に立ちましたか?

解決

はい、あなたはServletContextParameterFactoryBean値を公開するためにcontext-paramを使用することができます(それもPropertyPlaceholderConfigurerの完全な形の代わりに、簡単な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>

または使用の春3.0のELます:

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

他のヒント

完全axtavtに同意します。これにより春3.0と最も簡単な解決策を組み合わせたすべての情報は、次のとおりです。

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

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top