Open premcody opened 1 year ago
This is related to the new way of persisting job parameters in Spring Batch 5, see What’s New in Spring Batch 5.0 -> Support for any type as a job parameter.
By default, Spring Batch uses the DefaultConversionService
from Spring Framework, which does not support converting FilePart
to/from String out-of-the-box. So you need to register a converter for that type. If you use @EnableBatchProcessing
, you can register a bean of type ConfigurableConversionService
and add enrich the default conversion service with converters for the custom type:
@Configuration
@EnableBatchProcessing
class MyJobConfiguration {
@Bean
public ConfigurableConversionService conversionService() {
DefaultConversionService conversionService = new DefaultConversionService();
// add converter from String to FilePart and vice-versa in conversionService
return conversionService;
}
}
That said, any reason for using the FilePart
object as job parameter instead of the file name or path (as String)?
I really dont want to do file processing (read and write i/o) cause some performance in the batch processing. Its bummer that we couldn't able to retain something that was working before. We had few items others got broken due to this conversion.
You can get the same functionality if you provide a converter for FilePart
. Otherwise, as part of the migration to v5, I would recommend to take the opportunity to improve the design of your application's job parameters by using the file name/path as a job parameter instead of the file itself (so somehow, it is good that the new way of handling job parameters in Spring Batch 5 makes it difficult to implement a bad practice 😉).
I've tried to add FilePart Object to the JobParameterBuilder but getting the error "No Suitable Convertor to perform conversion from DefaultFilePart to String".
Here is the code snippet :
This was working atleast before (Spring-batch-core 4x versions) as i'd added FilePart as jobparameter using
addparamter
method but now failing with spring-batch-core 5.0.2 and spring-core-6.0.11.I think the problem is here the filepart is really not assignable to/from String as per the Spring-core code(JdbcJobExecutionDao,GenericConversionService & TypeDescriptor).
Adding the Stacktrace.