Skip to content
Advertisement

How to inject ObjectMapper in spring

I have a batch job written using Spring Batch

I have a config file below:

JavaScript

I have Json Line aggregator as below:

JavaScript

I want to inject objectMapper and don’t want to create it inside the JsonLineAggregator class. Any idea how can I implement it using DI ?

Advertisement

Answer

You can use @Autowired annotation to inject the dependency in spring like this:

JavaScript

And Spring will inject the ObjectMapper bean created by you in ObjectMapperConfig class

Advertisement