2016-10-07 3 views
0

Я работаю над проектом весенней загрузки, и мне нужно добавить проигрыватель интеграции Spring для опроса файлов из местоположения и запустить весеннюю партию в этом файле для его обработки.Конфигурация конфигурации интегратора Spring с загрузкой весны

Я использовал весной пакетную интеграцию для этого (порядкового номера документа ниже.)

http://docs.spring.io/spring-batch/trunk/reference/html/springBatchIntegration.html

Весной ботинок, я успешно настроил мой Poller в @Configuration файл, как показано ниже

@Bean 
@InboundChannelAdapter(value = "fileInputChannel", poller = @Poller(
    fixedRate = "1000"), autoStartup = "true") 
public MessageSource<File> filesScanner() { 
    CompositeFileListFilter<File> filters = new CompositeFileListFilter<File>(); 
    filters.addFilter(new SimplePatternFileListFilter("*.xml")); 
    filters.addFilter(new AcceptOnceFileListFilter<File>()); 
    filters.addFilter(getLastModifiedFileFilter()); 
    FileReadingMessageSource source = new FileReadingMessageSource(); 
    source.setDirectory(new File("F:/DataInput/")); 
    source.setFilter(filters); 
    return source; 
} 

Этот poller определен в java-конфигурации, тогда как каналы определены в xml, как показано ниже.

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:int="http://www.springframework.org/schema/integration" 
    xmlns:int-file="http://www.springframework.org/schema/integration/file" 
    xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd 
    http://www.springframework.org/schema/integration 
    http://www.springframework.org/schema/integration/spring-integration.xsd 
    http://www.springframework.org/schema/integration/file 
    http://www.springframework.org/schema/integration/file/spring-integration-file.xsd"> 
    <int:channel id="ticketingResponse" /> 
    <int:channel id="mailFailureTicketData" /> 
    <int:channel id="moveSuccessTicketingFile" /> 
    <int:channel id="moveFailureTicketingFile" /> 
    <int:channel id="ticketingFileInput" /> 
    <int:channel id="ticketingJobParameters" /> 
    <!-- <int-file:inbound-channel-adapter id="filePoller" 
    channel="inboundFileChannel" 
    directory="file:/tmp/myfiles/" 
    filename-pattern="*.csv"> 
    <int:poller fixed-rate="1000"/> 
</int-file:inbound-channel-adapter> --> 
    <bean id="earliestTicketingFileSelecter" class="com.avios.integration.iqcx.FilesSortingComparator" /> 
    <bean id="compositeFilesFilter" 
     class="org.springframework.integration.file.filters.CompositeFileListFilter"> 
     <constructor-arg> 
      <list> 
       <bean 
        class="org.springframework.integration.file.filters.RegexPatternFileListFilter"> 
        <constructor-arg name="pattern" value="${ticketing.input.file.pattern}" /> 
       </bean> 
       <bean class="org.springframework.integration.file.filters." /> 
       <bean 
        class="org.springframework.integration.file.filters.LastModifiedFileListFilter"> 
        <property name="age" value="${ticketing.input.file.age}" /> 
       </bean> 
      </list> 
     </constructor-arg> 
    </bean> 
    <bean id="ticketingFilesScanner" 
    class="org.springframework.integration.file.FileReadingMessageSource"> 
    <property name="filter" value="compositeFilesFilter" /> 
    <property name="directory" value="/tmp/myfiles/" /> 
</bean> 
<int-file:inbound-channel-adapter id="filePoller" 
    channel="inboundFileChannel" 
    directory="file:/tmp/myfiles/" 
    filename-pattern="*.csv"> 
    <int:poller fixed-rate="1000"/> 
</int-file:inbound-channel-adapter><!-- <int-file:inbound-channel-adapter 
     directory="${ticketing.input.file.path}" channel="ticketingFileInput" 
     comparator="earliestTicketingFileSelecter" auto-startup="true" filter="compositeFilesFilter" > 
     <int:poller ></int:poller> 
     </int-file:inbound-channel-adapter> --> 
    <int:transformer id="iqcxFilesToJobParameters" ref="jobParameterTransformer" 
     input-channel="ticketingFileInput" method="addTicketingFileToJobParameter" 
     output-channel="ticketingJobParameters" /> 
    <int:outbound-channel-adapter channel="ticketingJobParameters" 
     ref="iqcxJobLaunchingGateway" method="handleMessage" /> 

</beans> 

Я получаю следующую ошибку в файле конфигурации XML.

cvc-complex-type.3.2.2: В элементе 'int: poller' не разрешено указывать фиксированную скорость атрибута.

Я проверил это на google и нашел только ссылку ниже, которая была не очень полезной, так как я получаю точно такую ​​же ошибку.

Using Spring Boot & Spring Integration with database backed Configuration

Attribute 'fixed-rate' is not allowed to appear in element 'int:poller'

Spring версия загрузчика я использую, как показано ниже.

<groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.3.6.RELEASE</version> 

Весна интеграции банка в библиотеке - Spring-интеграция-ядро-4.2.8.RELEASE.jar

Я также попытался исключить интеграции баночку с пакетной интеграции зависимостей и добавление его отдельно, как показано ниже, но это тоже не сработало.

<dependency> 
     <groupId>org.springframework.batch</groupId> 
     <artifactId>spring-batch-integration</artifactId> 
     <exclusions> 
      <exclusion> 
       <groupId>org.springframework.integration</groupId> 
       <artifactId>spring-integration-core</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 
    <!-- https://mvnrepository.com/artifact/org.springframework.integration/spring-integration-core --> 
    <dependency> 
     <groupId>org.springframework.integration</groupId> 
     <artifactId>spring-integration-core</artifactId> 
     </dependency> 

Также проверил XSD http://www.springframework.org/schema/integration/spring-integration.xsd и имеет атрибут фиксированной задержки в Poller. Любые предложения по разрешению этого?

ответ

0

Прочитайте важное замечание в онлайн-схеме:

+++++ +++++ ВАЖНОЕ

This schema is for the 1.0 version of Spring Integration Core. We cannot update it to the current schema 
because that will break any applications using 1.0.3 or lower. For subsequent versions, the unversioned 
schema is resolved from the classpath and obtained from the jar. 
Please refer to github: 

https://github.com/spring-projects/spring-integration/tree/master/spring-integration-core/src/main/resources/org/springframework/integration/config/xml

for the latest schema. 

В старом схема, фиксированная скорость была частью периодического дочернего элемента триггера на poller.

Схема 4.2: here.

Если это только ошибка IDE, вы можете игнорировать ее или настроить свою среду IDE на «весну».

Весна находит фактическую схему на пути к классам.

С помощью STS включить «весенний характер» в проекте.

+0

IDE была проблема. Я запустил приложение с ошибкой, все еще там, в XML, и он успешно работал с конфигурацией XML. Раньше не пытался. Спасибо за ваше предложение. – Raghav

+0

Попробуйте включить природу Spring в STS4: https://stackoverflow.com/questions/49201689/enable-spring-project-nature-in-sts-4/49201841#49201841 без везения. Какие-либо предложения? TIA –

0

Иногда это может быть из-за отсутствия интеграции с пружинным загрузочным стартером. & зависимая от spring-integration-file в pom.xml. Поэтому проверьте, действительно ли зависимость spring-integration-file доступна в вашем проекте, когда вы используете интеграцию с весной.

+0

Если бы это была проблема зависимостей, моя аннотация, основанная на конфирмации, также потерпела бы неудачу. Но это работает без ошибок. Проблема связана только с конфигурацией XML. Также, по предложению Гэри, я запустил приложение с ошибкой, все еще находящейся в XML, и приложение успешно работало. – Raghav

+0

О, хорошо, я не был уверен, что вы получаете это во время работы. У меня была аналогичная проблема в выходные, когда я пытался перенести существующий проект на весеннюю загрузку. рад, что ты обошел его. –