2015-10-15 3 views
2

у меня fileMessageProvider() какSpring Integration SPEL проблемы с аннотацией

@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", он работает хорошо.

Моя весна версия интеграции '4.0.0.RELEASE'

Update: 1

Я использую смесь аннотаций и XML-конфигурации

Batch.properties

my.poller.interval=20000 

integration-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> 
+0

Попробуйте использовать # {<строка выражения>} insted {# <строка выражения>} – Fincio

+0

Tried fixedDelay = "# {my.poller.interval}" дает аналогичное исключение java.lang.NumberFormatException: для строки ввода: "# {my.poller.interval} " – Sam

+0

Изменить # на $. Он должен выглядеть как '$ {my.poller.interval}'. Это работает, конечно, если у вас есть объект 'my', у которого есть свойство' pooler', свойство 'interval'. – wawek

ответ

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

Но да: я должен подтвердить, что он перестает работать должным образом, если мы указываем <context:property-placeholder> в XML config вместо @PropertySource на классе @Configuration.

Я не могу вспомнить конкретную 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

С другой стороны, я нашел, как сделать его работу с Рамочной точки зрения.

Итак, это ошибка, и я поднимаю JIRA по этому вопросу.

Благодарим за обмен опытом!

+0

С @PropertySource мое требование работает хорошо. Спасибо за поддержку. Я рад, что я смог поднять эту ошибку. – Sam

Смежные вопросы