Spring集成SpEL与注释有关

时间:2015-10-15 12:57:20

标签: java spring-integration

我的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}"

而不是SpEL如果我使用fixedDelay =&#34; 10000&#34; ,它运作良好。

My Spring集成版本&#39; 4.0.0.RELEASE&#39;

更新: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>

1 个答案:

答案 0 :(得分:1)

我们在这个问题上有类似的测试用例,并且正是因为这个功能的提升:

    @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>而不是@PropertySource类上的@Configuration,我必须确认它已停止正常工作。

我无法回忆起有关此问题的特定JIRA,但我记得,通过注释和XML配置组合,第一个具有优先权,并且必须在@Configuration类中配置环境。 / p>

对于我的样本,它看起来像:

@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();
    }   

}

<强>更新

从另一方面,我发现了如何从Framework的角度来看它。

所以,这是一个错误,我在这个问题上提出JIRA

感谢您分享您的经验!