Results 1 to 10 of 11

Thread: Problem autowiring ItemWriter defined with scope="step"

Hybrid View

  1. #1
    Join Date
    Oct 2012
    Location
    Madrid
    Posts
    20

    Question Problem autowiring ItemWriter defined with scope="step"

    Hi,

    I have a problem when I try to @Autowired a bean of type FlatFileItemWriter. I need to calculate a directory name in execution time and assign this value to the "resource" property using late-binding. There's no problem to achive this, but, when my batch runs, I receive an exception when Spring context tries to @Autowired this bean inside my ItemProcessor (I need to use it directly in the ItemProcessor for functional design)

    The exception is: There are many candidates of type org.springframework...FlatFileItemWriter.

    If I use the @Qualifier then the error refers to another bean that has no sense with that error.




    Thanks,

  2. #2
    Join Date
    Sep 2008
    Location
    Chicagoland, IL
    Posts
    338

    Default

    Crazy question...why are you trying to wire an ItemReader into an ItemProcessor? Why not use just a regular DAO? There is no benefits of using an ItemReader in this way.
    Michael Minella
    Spring Batch Lead
    Author - Pro Spring Batch
    http://www.michaelminella.com
    Twitter: @MichaelMinella

  3. #3
    Join Date
    Oct 2012
    Location
    Madrid
    Posts
    20

    Default

    Hi mminella,

    I am autowiring an ItemWriter NOT an ItemReader.


    Thanks,
    Last edited by maxjuiz; Oct 31st, 2012 at 04:22 AM.

  4. #4
    Join Date
    Sep 2008
    Location
    Chicagoland, IL
    Posts
    338

    Default

    Either way, my question is valid. You shouldn't be trying to wire up ItemReader/ItemWriter components into your ItemProcessor. They carry extra weight that is unused and unnecessary. Just create and inject a DAO of somekind.
    Michael Minella
    Spring Batch Lead
    Author - Pro Spring Batch
    http://www.michaelminella.com
    Twitter: @MichaelMinella

  5. #5
    Join Date
    Oct 2012
    Location
    Madrid
    Posts
    20

    Default

    My ItemWriter works as "delegate". I couldn't write items during the process because I need to process all the items first to do some operations.

    But the main question isn't the design of the process, the main question is why do an ItemWriter cannot be autowired if this bean is defined with late-binding? Spring Batch bug?



    Thanks,

  6. #6
    Join Date
    Sep 2008
    Location
    Chicagoland, IL
    Posts
    338

    Default

    The function of autowiring isn't one of batch but of spring core, so it wouldn't be a batch bug. Can you post the code you're working with?
    Michael Minella
    Spring Batch Lead
    Author - Pro Spring Batch
    http://www.michaelminella.com
    Twitter: @MichaelMinella

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •