Parameter 0 of method jobBean in com.nextuple.BatchProcessing.config.BatchConfig required a bean named 'dataSource' that could not be found

20 views Asked by At

So actually I am developing a Springboot application to read a static csv file and put the data into MongoDB after performing some small processing. Any help would be greatly appreciated. This is the error message

Description:

Parameter 0 of method jobBean in com.nextuple.BatchProcessing.config.BatchConfig required a bean named 'dataSource' that could not be found.

Action:

Consider defining a bean named 'dataSource' in your configuration.

These are the Configuration files that I have created

@Configuration
@EnableBatchProcessing
public class BatchConfig {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Bean
    public Job jobBean(JobRepository jobRepository,JobCompletionNotificationImpl listener,
                       Step step){
        return new JobBuilder("job",jobRepository)
                .listener(listener)
                .flow(step)
                .end()
                .build();
    }

    @Bean
    public Step step(JobRepository jobRepository, MongoTransactionManager transactionManager, ItemReader<Product> reader,
                     ItemProcessor<Product,Product> processor, ItemWriter<Product>writer){
        return new StepBuilder("jobStep",jobRepository)
                .<Product,Product>chunk(5,transactionManager)
                .reader(reader)
                .processor(processor)
                .writer(writer)
                .build();

    }

    @Bean
    public FlatFileItemReader<Product> reader(){
        return new FlatFileItemReaderBuilder<Product>()
                .name("itemReader")
                .resource(new ClassPathResource("data.csv"))
                .linesToSkip(1)
                .delimited()
                .names("title", "description", "price", "discount")
                .targetType(Product.class)
                .build();
    }

    @Bean
    public ItemProcessor<Product,Product>itemProcessor(){
        return new CustomItemProcessor();
    }

    @Bean
    public ItemWriter<Product> itemWriter(){
       return list ->{
           for(Product product:list)
               mongoTemplate.save(product);
       };
    }
}

this is the ItemProcessor file where the processing is being performed

    @Override
    public Product process(Product item) throws Exception {
       //logic to transform the data
        try {
//            put the percentage logic
            System.out.println(item.getDescription());
            int discountPer = Integer.parseInt(item.getDiscount().trim());
            double originalPrice = Double.parseDouble(item.getPrice().trim());
            double discount = ((double) discountPer / 100) * originalPrice;
            double finalPrice = originalPrice - discount;
            item.setDiscountedPrice(String.valueOf(finalPrice));
        } catch (
                NumberFormatException ex
        ) {
            ex.printStackTrace();
        }

        return item;
    }

}

this is the yml file application.properties

spring.application.name=BatchProcessing
spring.data.mongodb.uri=mongodb://localhost:27017/batch
spring.data.mongodb.auto-index-creation=true
server.port=8080
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration ```

Please let me know if any further details are required.
0

There are 0 answers