Skip to content

Tag: dependency-injection

How to inject ObjectMapper in spring

I have a batch job written using Spring Batch I have a config file below: I have Json Line aggregator as below: 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 ? Answer You can use @Autowired annotation to inject the dependency in spring like

Spring: re-initialized a bean

This is my Spring bean in the configuration class that creates a gRPC ManagedChannel: The controller method is provided below: The service class is: For each request, I create a new ManagedChannel in the service method processRequest and shut it down using the method called shutdownManagedChannel. Earlier, I try to use the @Autowired for the managed channel as below: This

How to test a Java/Spring service using RestTemplate without calling external API and by using Dependency Injection?

In my Spring application, i have a service MyService. MyService calls an external API, counts the products there and returns the result. To call that API it uses the Spring module RestTemplate. To inject the RestTemplate it is configured as @Bean in the DependencyConfig: Now i want to test it, without calling the external API. So i inject the MyService

Dagger Dependency Injection Provider with Qualifier

I’d like to get a confirmation that: if two providers providing the same type of instance, one with qualifier and the other one without, would this work? For the following two cases, especially the TestClass1, will Dagger know which MetricsCollectorFactory to inject? Answer Yes, as on the Dagger dev guide, there are zero or one qualifier instances per key or