Announcement Announcement Module
Collapse
No announcement yet.
IllegalArgumentException when creating FixedLengthTokenizer Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • IllegalArgumentException when creating FixedLengthTokenizer

    I have a FixedLengthTokenizer for a FlatFileItemReader like so:

    Code:
    <bean id="itemReader" class="org.springframework.batch.item.file.FlatFileItemReader">
       <property name="resource" value="classpath:data/72ack.2007070231542.out"></property>
       <property name="lineTokenizer" ref="fixedFileTokenizer" />
       <property name="fieldSetMapper">
          <bean class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper" >
             <property name="prototypeBeanName" value="ack" />
          </bean>
       </property>
    </bean>
    <bean id="fixedFileTokenizer"
       class="org.springframework.batch.item.file.transform.FixedLengthTokenizer">
       <property name="names" value="linkageNumber,contact,paymentType,returnReasonCode,paymentAmount" />
       <property name="columns" value="1-21,22-51,52-53,54-56,57-68" />
    </bean>
    But when initializing the container, I get an IllegalArgumentException when Spring tries to create the columns Range[] from the provided String in the FixedLengthTokenizer.

    Code:
    [some exceptions omitted]
    Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [org.springframework.batch.item.file.transform.Range[]] for property 'columns'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String] to required type [org.springframework.batch.item.file.transform.Range] for property 'columns[0]': no matching editors or conversion strategy found
       at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:391)
       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1253)
       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1214)
       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:978)
       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:462)
       ... 46 more
    Caused by: java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String] to required type [org.springframework.batch.item.file.transform.Range] for property 'columns[0]': no matching editors or conversion strategy found
       at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:238)
       at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:124)
       at org.springframework.beans.TypeConverterDelegate.convertToTypedArray(TypeConverterDelegate.java:385)
       at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:205)
       at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138)
       at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:386)
       ... 50 more
    Why can't Spring figure out that it needs to use a RangeArrayPropertyEditor? (Assuming that's what it should be.) I'm doing this the way the Batch docs show, and they don't mention having to jump through extra hoops to force the use of a certain PropertyEditor, so what's up? I've tried the column and names properties with and without spaces between values. Fails the same either way.

  • #2
    Which version of Spring are you using?

    Comment


    • #3
      Spring 2.5.3 (probably) and Spring Batch 1.0 Final. I think I just copied all the libs from Spring Batch (alldeps zip) into my classpath, so if the core Spring jars were included with Batch, then I used whatever version those were. Otherwise it was 2.5.3 for sure. I'm not at that computer at the moment.

      Win32
      Java 5

      Comment


      • #4
        The Samples have the following entry in simple-job-launcher-context.xml:

        Code:
        	<bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer">
        		<property name="customEditors">
        			<map>
        				<entry key="int[]">
        					<bean class="org.springframework.batch.support.IntArrayPropertyEditor" />
        				</entry>
        				<entry key="org.springframework.batch.item.file.transform.Range[]">
        					<bean class="org.springframework.batch.item.file.transform.RangeArrayPropertyEditor" />
        				</entry>
        				<entry key="java.util.Date">
        					<bean class="org.springframework.beans.propertyeditors.CustomDateEditor">
        						<constructor-arg>
        							<bean class="java.text.SimpleDateFormat">
        								<constructor-arg value="yyyyMMdd" />
        							</bean>
        						</constructor-arg>
        						<constructor-arg value="false" />
        					</bean>
        				</entry>
        			</map>
        		</property>
        	</bean>
        For some reason I thought this was necessary in 2.0 but not in 2.5, although Dave would better be able to answer that question than I. You're right that it should be documented that it's necessary. I think we were originally hoping to handle this with a namespace, which got scrapped for other reasons.

        Comment


        • #5
          Thanks. That did the trick.

          Comment

          Working...
          X