不幸的是,Spring XD似乎没有附带XML类型转换器(application/xml
)。
我实现了2 AbstractFromMessageConverter
用于将POJO转换为XML,反之亦然。
根据documentation,它说要查看streams.xml,我认为它们实际上指的是this XML。我提供了一个名为customMessageConverters
的列表和我自己的配置,它公开了这些转换器,试图将它们添加到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
中取消注释了这些行,并将基本包更改为我的。
---
# 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
---
答案 0 :(得分:1)
您必须将文件放在一个狭窄的文件夹中,例如罐子里的/myCustomConverters
;那么你必须通过取消注释serverys.yml
...
# 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: com.acme.xd.extensions
# locations: META-INF/spring-xd/ext
locations: myCustomConverters