0

私は比較的単純な味で任務を負っていましたが、この時点で立ち往生しました。私の質問は

これら 2 つの構文は同じですか?

<context:property-placeholder location="classpath:application.properties" system-properties-mode="OVERRIDE"/> 

B

<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="classpath:application.properties"/>
    <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
</bean>

AppContext

<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.1.xsd
    http://www.springframework.org/schema/security
    http://www.springframework.org/schema/security/spring-security-3.1.xsd"
>

で、結果はこちら

 https://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
4

2 に答える 2

2

Spring 3.1 のバージョン (xml スキーマで参照されている) では、それらはまったく同じではありません

context:property-placeholderbean 宣言でインスタンスをPropertySourcesPlaceholderConfigurer 宣言した whileのインスタンスを定義します。PropertyPlaceHolderConfigurer

そのため、Bean を直接宣言する代わりにタグを使用することが妥当な場合があります (つまり、どのように行うかではなく、何を行うかを定義ます)

PropertySourcesPlaceholderConfigurer javadoc から:

Spring 3.1 以降、この実装よりも PropertySourcesPlaceholderConfigurer を優先的に使用する必要があります。Spring 3.1 で利用可能になった Environment および PropertySource メカニズムを利用することで、より柔軟になります。

Spring 3.1 より前では、namespace 要素は PropertyPlaceholderConfigurer のインスタンスを登録していました。名前空間の spring-context-3.0.xsd 定義を使用する場合は、引き続きそうします。つまり、Spring 3.1 を使用している場合でも、名前空間を通じて PropertyPlaceholderConfigurer の登録を保持できます。xsi:schemaLocation を更新せずに、3.0 XSD を引き続き使用してください。

于 2013-01-29T09:35:31.647 に答える
0

はい、同じです。

コンテキスト名前空間のドキュメントによる

「OVERRIDE」は、プレースホルダーを最初にシステムプロパティに対して解決し、次にローカルプロパティに対して解決する必要があることを示します

PropertyPlaceholderConfigurerによる

指定されたプロパティを試す前に、まずシステムプロパティを確認してください。これにより、システムプロパティが他のプロパティソースを上書きできるようになります。

于 2013-01-29T09:28:05.960 に答える