Learnitweb

Category: Spring Core

  • Spring @EntityScan vs. @ComponentScan

    1. Introduction When creating Spring applications we might need to specify a list of packages that contain our entity classes. Similarly, we might need to specify list of Spring beans to be initialized. We use the annotations @EntityScan and @ComponentScan annotations. In this short tutorial, we’ll discuss the cases where @EntityScan and @ComponentScan annotations are…

  • Spring @Bean annotation

    1. Introduction In this tutorial, we’ll discuss @Bean annotation which is a very important annotation to know. A Java object instance managed by Spring container is called bean. This annotation is typically used to define methods to create beans. Following is the declaration of @Bean annotation: This annotation is used on a method and indicates…

  • @Controller and @RestController annotation in Spring

    1. Introduction In this tutorial, we’ll discuss the difference between @Controller and @RestController annotations in Spring MVC. The @Controller annotation is available since Spring 2.5 whereas @RestController was introduced in Spring 4.0 to simplify creation of RESTful web services. 2. @Controller annotation This annotation is a specialization of @Component and indicates that the annotated class…

  • Spring @Primary annotation

    1. Introduction In this quick tutorial, we’ll discuss Spring’s @Primary annotation. The @Primary annotation indicates that a bean should be given preference when multiple candidates are qualified to autowire a single-valued dependency. If there is exactly one bean annotated with @Primary among the candidates, it will be used for autowiring. This annotation may be used…

  • Spring @Qualifier annotation

    1. Introduction In this tutorial, we’ll discuss what is the use of @Qualifier annotation and which problem it solves. In this tutorial we’ll also discuss how @Qualifier is different from @Primary annotation. 2. What problem does @Qualifier solve? While autowiring beans, Spring by default searches by types and does the bean injection. However, Spring may…

  • Circular dependency in Spring with example

    Overview In this tutorial, we’ll discuss circular dependency in Spring with example. Circular dependency generate exception while creating beans. We’ll create a circular dependency and will see how to fix this. Circular dependency in Spring Before looking at circular dependency, we need to understand how beans are created by container. Container is intelligent enough to…

  • Overview of dependency injection in Spring

    Overview In this tutorial, we’ll take a look at the concept of Dependency Injection and IoC (Inversion of Control). We’ll see types of Dependency Injection in Spring and how it is implemented in Spring. We’ll have separate tutorials for each type of Dependency Injection. In this tutorial, we’ll look at all these topics briefly. Inversion…

  • Instantiation of bean by using an instance factory method in Spring

    Spring allows instantiation of bean using instance factory method. Using instance factory allows to keep separate the logic to create the bean separate. In this article we’ll discuss the instantiation of bean by using instance factory method in Spring. Instantiation with an instance factory method invokes the non-static method of the existing bean in the…

  • Instantiation of bean with a Static Factory Method in Spring

    Spring allows following three ways to instantiate beans: Instantiation with a constructor Instantiation with a static factory method Instantiation by using an instance factory method In this article we’ll discuss instantiation with a static factory method. When defining configuration for a bean which is created with a static factory method, we use two attributes class…

  • Overview of bean in Spring and naming beans

    Beans in application are same as bricks in house. A bean is an object of your application. An application is made of several beans. A bean is an object which is instantiated, assembled (refers to injection of dependencies) and managed by Spring IoC container. IoC container instantiates, assembles and manages the beans using the configuration…