【问题标题】:Spring Integration SpEL issues with annotation带有注释的 Spring Integration SpEL 问题
【发布时间】:2015-10-15 12:57:20
【问题描述】:

我的 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 配置的组合

批处理属性

my.poller.interval=20000

集成上下文.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>

【问题讨论】:

  • 尝试使用#{ } insted {# }
  • Tried fixedDelay = "#{my.poller.interval}" 给出了类似的异常 java.lang.NumberFormatException: For input string: "#{my.poller.interval}"
  • 将 # 更改为 $。它应该看起来像${my.poller.interval}。当然,如果您有 my 具有 pooler 属性且具有 interval 属性的对象。
  • 您可以发布您的财产文件吗?以及你阅读它的方式?
  • 尝试使用 fixedDelay = "${my.poller.interval}"。这是这种情况下的异常消息 java.lang.NumberFormatException: For input string: "${my.poller.interval}"

标签: java spring-integration


【解决方案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 配置中指定 &lt;context:property-placeholder&gt; 而不是在 @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();
    }   

}

更新

从另一方面,我发现了如何从框架的角度使其工作。

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

感谢您分享您的经验!

【讨论】:

  • 使用@PropertySource 我的要求运行良好。谢谢你的支持。我很高兴我能提出这个错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多