Spring Dependency Injection Dependency Injection is a fundamental aspect of the Spring framework, through which the Spring container “injects” objects into other objects or “dependencies”. Simply put, this allows for loose coupling of components and moves the responsibility of managing components onto the container. Let’s explore DI with Spring further… Continue Reading spring-dependency-injection

Spring NoSuchBeanDefinitionException 1. Overview In this article, we are discussing the Spring org.springframework.beans.factory.NoSuchBeanDefinitionException – this is a common exception thrown by the BeanFactory when trying to resolve a bean that simply isn’t defined in the Spring Context. We’ll illustrate the possible causes for this problem and the available solutions. And… Continue Reading spring-nosuchbeandefinitionexception

Injecting Prototype Beans into a Singleton Instance in Spring Spring Spring DI 1. Overview In this quick article, we’re going to show different approaches of injecting prototype beans into a singleton instance. We’ll discuss the use cases and the advantages/disadvantages of each scenario. By default, Spring beans are singletons. The… Continue Reading spring-inject-prototype-bean-into-singleton

Injecting Mockito Mocks into Spring Beans 1. Overview This article will show how to use dependency injection to insert Mockito mocks into Spring Beans for unit testing. In real-world applications, where components often depend on accessing external systems, it is important to provide proper test isolation so that we can… Continue Reading injecting-mocks-in-spring

Constructor Dependency Injection in Spring 1. Introduction Arguably one of the most important development principles of modern software design is Dependency Injection (DI) which quite naturally flows out of another critically important principle: Modularity. This article will explore a specific type of DI technique called Constructor-Based Dependency Injection within Spring… Continue Reading constructor-injection-in-spring

Intro to Inversion of Control and Dependency Injection with Spring 1. Overview In this article, we’ll introduce the concepts of IoC (Inversion of Control) and DI (Dependency Injection), and we’ll then take a look at how these are implemented in the Spring framework. Further reading: Wiring in Spring: @Autowired, @Resource… Continue Reading inversion-control-and-dependency-injection-in-spring

Unsatisfied Dependency in Spring 1. Overview In this quick tutorial, we’ll explain Spring’s UnsatisfiedDependencyException, what causes it, and how to avoid it. 2. Cause of UnsatisfiedDependencyException UnsatisfiedDependencyException gets thrown when, as the name suggests, some bean or property dependency isn’t satisfied. This may happen when Spring application tries to wire a bean and cannot… Continue Reading spring-unsatisfied-dependency