Categories
Spring Spring Core

Dependency Injection using @Inject and @Named Annotations

We have many ways to Inject Dependencies in Spring. XML Configuration, @Autowired Annotation, @Resource annotation are few of them. Among these methods we have JSR 330 Standard annotations as well. We can choose any one of these based on our application needs. Key Points : @Inject can be used instead of @Autowired and @Resource annotations […]

Categories
Spring Spring Core

Generics as Auto-wiring Qualifiers

When we are using more than one implementation for a Type, we use @Qualifier annotation as explained in this article. We don’t want to use @Qualifier annotation when using Generics as shown in the below example. Step 1 : Create Maven project and name it as GenericsAsQualifiers and copy below dependencies in pom.xml file. Step […]

Categories
Spring Spring Core

Spring Annotation Based container configuration

In Spring Framework we have three different ways to configure an IoC Container. XML Based Container Configuration Bean configuration will be in the form of XML meta-data. Refer this example for better understanding. Annotation Based Container Configuration Annotations will be used to configure each bean and its properties. Java Based Container Configuration Using Java Based […]

Categories
Spring Spring Core

Stereotype Annotations in Spring and Spring Boot

The @Component, @Controller, @Service and @Repository are the Stereotype annotations of Spring and Spring Boot Instead of providing Bean Definitions in XML Configuration file Spring provides these Stereotype annotations that can be defined in Java class itself.  Spring Automatically detects Stereotyped classes and configured with the ApplicationContext. As per the above diagram, @Controller, @Service and […]

Categories
Spring Spring Core

Custom Qualifier Annotation

In this article I’m going to explain how to create customized Qualifiers in spring with example code. Instead of using @Qualifier annotation with name as a parameter everywhere, you can customize the Qualifier annotation for you based on the nature of your application. For Example : Mine is a Course management application for colleges. Every […]

Categories
Spring Spring Core

Dependency Injection with @Resource annotation

Key Terms As like Autowired annotation Resource will resolve and inject dependencies.  Unlike Autowired annotation, it will search by Name. Means, It will take Field Name and Setter-Method parameter name to resolve dependencies. Name or ID of the Bean should be provided in XML or @Bean configuration. XML <bean id=”…” class=”…”></bean> @Bean @Bean(“…”) You can […]

Categories
Spring Spring Core

Spring Qualifier Annotation

Generally Autowired annotation will resolve dependencies based on the Type. If you are having only one Class implementing an interface, then Spring will make use of the Class implementation to resolve dependency. But, in most of the scenarios we have more than one Implementation classes for an Interface. If you use @Autowired in this case, […]

Categories
Spring Spring Core

Auto-wiring with Example

In Spring you can Inject Dependencies either in the form of XML or Annotation or Java Code. In this Article we are going to look at how Injection made possible using Autowired annotation and different possible types of Autowiring in Spring with working examples. Auto-wiring in Spring Types Autowiring by Constructor Autowiring by Setter-Method Autowiring […]

Categories
Spring Spring Core

Spring Bean Life Cycle Callback Methods

As per our Bean Definition in the form of “XML, Java Code or Annotation” the IoC Container will Create, Assemble and Instantiate the Bean Objects for you and it destroys when the Container is Shutdown in case of Singleton and it destroys when Object is no longer needed in case of Prototype Scope.  If you […]