[英]Reuse XML fragment of a bean
我有一個xml文件可以滿足我的需要,但是它有很多重復的代碼。 例如-用戶名和密碼是xml文件中每個bean的一部分。 我創建了以下帶有parentBean
id的文件,希望可以重用子bean中的所有內容。 但是我得到The content of element type "bean" must match
錯誤。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="parentBean" class="com.dataloader.ProcessRunner" abstract="true">
<description>Parent bean.</description>
<map>
<entry key="sfdc.debugMessages" value="true" />
<entry key="sfdc.debugMessagesFile" value="C:\DLTest\accountExportSoapTrace.log" />
<entry key="sfdc.endpoint" value="https://test.com" />
<entry key="sfdc.username" value="test" />
<entry key="sfdc.password" value="5b69d70a1dd974a21ecf64595ac02596f0c7c" />
<entry key="process.encryptionKeyFile" value="D:\SF\dataLoader.key" />
<entry key="sfdc.timeoutSecs" value="600" />
</map>
</bean>
<bean id="account" singleton="false" parent="parentBean">
<description>accountInsert exports all fields from the Account object.</description>
<property name="name" value="account" />
<property name="configOverrideMap">
<map>
<entry key="sfdc.entity" value="Account" />
<entry key="process.operation" value="extract" />
<entry key="sfdc.extractionSOQL" value="SELECT ID, Name, Phone FROM Account" />
<entry key="process.mappingFile" value="D:\SF\accountExport.sdl" />
<entry key="dataAccess.name" value="D:\SF\Account.csv" />
<!--entry key="process.outputSuccess"
value="c:\DLTest\accountExport_success.csv"/>
<entry key="process.outputError"
value="c:\DLTest\Log\accountExport_error.csv"/-->
<entry key="dataAccess.type" value="csvWrite" />
<entry key="process.initialLastRunDate" value="2018-10-1T00:00:00.000-0800" />
</map>
</property>
</bean>
<bean id="contact" singleton="false" parent="parentBean">
<description>contactExport exports all fields from the Contact object.</description>
<property name="name" value="contact" />
<property name="configOverrideMap">
<map>
<!--entry key="sfdc.loadBatchSize" value="200"/-->
<entry key="sfdc.entity" value="Contact" />
<entry key="process.operation" value="extract" />
<entry key="sfdc.extractionSOQL" value="SELECT ID, FirstName, LastName FROM Contact" />
<entry key="process.mappingFile" value="D:\SF\contactExport.sdl" />
<entry key="dataAccess.name" value="D:\SF\Contacts.csv" />
<entry key="dataAccess.type" value="csvWrite" />
<entry key="process.initialLastRunDate" value="2018-10-1T00:00:00.000-0800" />
</map>
</property>
</bean>
</beans>
您需要在父bean上指定屬性名稱。 要合並來自父bean和子bean的映射,請在beans元素上設置屬性default-merge="true"
。
即
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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.xsd"
default-merge="true">
<bean id="parentBean" class="com.dataloader.ProcessRunner" abstract="true">
<description>Parent bean.</description>
<property name="configOverrideMap">
<map>
<entry key="sfdc.debugMessages" value="true" />
<entry key="sfdc.debugMessagesFile" value="C:\DLTest\accountExportSoapTrace.log" />
<entry key="sfdc.endpoint" value="https://test.com" />
<entry key="sfdc.username" value="test" />
<entry key="sfdc.password" value="5b69d70a1dd974a21ecf64595ac02596f0c7c" />
<entry key="process.encryptionKeyFile" value="D:\SF\dataLoader.key" />
<entry key="sfdc.timeoutSecs" value="600" />
</map>
</property>
</bean>
... rest of the applicationContext
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.