不幸的是,似乎Spring XD沒有附帶XML類型轉換器(application/xml
)。將自定義類型轉換器添加到Spring XD
我實現了2 AbstractFromMessageConverter
s用於將POJO轉換爲XML,反之亦然。
根據documentation它說看看streams.xml我認爲他們真的指的是this XML。我提供了一個名爲customMessageConverters
的列表和我自己的Configuration,它們公開了這些轉換器,試圖將它們添加到Spring XD應用程序上下文中。
我寫道:
@Configuration
@Slf4j
public class XmlConverterConfiguration {
@Bean
public CompositeMessageConverter compositeMessageConverter(final MessageConverter[] converters) {
log.info("Registering XML converters");
return new CompositeMessageConverter(Arrays.asList(converters));
}
}
我加入@Component
註釋到我的轉換器。
而且也是這個XML:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<!-- Users can override this to add converters.-->
<util:list id="customMessageConverters">
<bean class="my.custom.mime.converter.PojoToXmlMessageConverter"/>
<bean class="my.custom.mime.converter.XmlToPojoMessageConverter"/>
</util:list>
</beans>
,我試圖加入這個XML來src/main/resources
和src/main/resources/config
,然後我把編譯後的.jar到$XD_HOME/lib
但它不會正確註冊。
我沒有看到我的配置日誌,當我嘗試設置outputtype設置爲application/xml
我得到一個例外,它不支持:
org.springframework.xd.dirt.plugins.ModuleConfigurationException: Content type is not supported for outputType=application/xml
哪一步我做錯?
- 編輯 -
我也註釋掉在server.yml
這些線,改變了basepackages礦。
---
# User Extensions: Where XD scans the classpath to discover extended container configuration to add beans to the Plugins context.
# Each property may be a comma delimited string. 'basepackages' refers to package names used for
# annotated component (@Configuration or @Component stereotypes) scanning. 'locations' is a list of root resource directories containing XML or Groovy configuration.
# XD prepends classpath:* if no prefix included and appends **/*.* to each location
xd:
extensions:
basepackages: my.custom.mime.converter
locations: META-INF/spring-xd/ext
---
忘了提我註釋掉在servers.yml所提供的線路,改變了basepackages雷:my.custom.mime .converter。 現在明白了,真的很欣賞快速反應。 – aturkovic
您不需要基礎包,您需要告訴XD如何使用'customMessageConverters' bean來查找xml。 –
我仍然無法使它工作。我刪除了我的配置並從我的轉換器中刪除了@Component註釋,並將我的XML放在/ resources/extension-config文件夾中。我還通過註釋basepack來配置我的servers.yml,因爲你說我不需要它們,我將位置更新到extension-config文件夾。仍然沒有運氣,他們沒有正確註冊。還有什麼我失蹤? – aturkovic