それはcontextConfigLocationパラメーターと一緒にweb.xmlに.propertiesファイルを使用することは可能ですか?
-
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の
所属していません StackOverflow