Spring 集成 SpEL 注释问题

Spring Integration SpEL issues with annotation

我有我的 fileMessageProvider() 作为

@InboundChannelAdapter( value = "files" , poller = @Poller(  fixedDelay = "${my.poller.interval}", maxMessagesPerPoll = "1"  ))
 public Message<File> fileMessageProvider() {
    ...
 }

部署时出现 NumberFormatException

Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myPoller' defined in "../MyPoller.class": Initialization of bean failed; nested exception is java.lang.NumberFormatException: For input string: "{#my.poller.interval}"

如果我使用 fixedDelay = "10000" 而不是 SpEL,效果很好。

我的 Spring 集成版本 '4.0.0.RELEASE'

更新:1

我混合使用注释和 xml 配置

Batch.properties

my.poller.interval=20000

整合-context.xml

<context:property-placeholder location="classpath:Batch.properties"/>
<context:component-scan base-package="com.org.reader" />

<int:transformer  input-channel="files" output-channel="requests">
    <bean class="com.org.reader.MyMessageToJobRequest">
        <property name="job" ref="addMessages"/>
    </bean>
</int:transformer>

我们在这个问题上有类似的测试用例,并且恰好是在提出此功能后:

    @Override
    @ServiceActivator(inputChannel = "input", outputChannel = "output",
            poller = @Poller(maxMessagesPerPoll = "${poller.maxMessagesPerPoll}", fixedDelay = "${poller.interval}"))
    @Publisher
    @Payload("#args[0].toLowerCase()")
    @Role("foo")
    public String handle(String payload) {
        return payload.toUpperCase();
    }

但是是的:如果我们在 XML 配置中指定 <context:property-placeholder> 而不是在 @Configuration [=] 中指定 @PropertySource,我必须确认它停止正常工作35=].

我记不起关于此事的具体 JIRA,但我记得注释和 XML 配置组合,第一个优先,环境必须在 @Configuration class.

对于我的示例,它看起来像:

@Configuration
@ComponentScan
@IntegrationComponentScan
@EnableIntegration
@PropertySource("classpath:org/springframework/integration/configuration/EnableIntegrationTests.properties")
@ImportResource("classpath:org/springframework/integration/configuration/EnableIntegrationTests-context.xml")
@EnableMessageHistory({"input", "publishedChannel", "annotationTestService*"})
public class ContextConfiguration {

    @Bean
    public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }   

}

更新

从另一方面,我找到了如何从框架的角度让它工作。

所以,这是一个错误,我正在就此事提出 JIRA

感谢您分享您的经验!