繁体   English   中英

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

而不是SpEL如果我使用fixedDelay =“10000”,它的效果很好。

我的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 ,我必须确认它会停止正常工作。

我不记得有关此问题的特定JIRA,但我记得在注释和XML配置组合中,第一个具有优先权,并且必须在@Configuration类中配置环境。

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

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

}

UPDATE

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

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

感谢您分享您的经验!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM