In this post under Spring Core, I will explain with example the purpose of “required” attribute of “@Autowired” annotation. When we tell Spring framework to wire two beans say “Bean2” to “Bean1” as shown below package package20;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Component;@Componentpublic class Bean1 { @Autowired private Bean2 bean2; public Bean2 getBean2() { return bean2; } public void…… Continue reading “required” attribute of @Autowired annotation
Category: Spring Framework
Example of @Autowired (setter injection approach 2)
In this post under Spring Core, I will show another approach of achieving setter injection using “@Autowired” annotation. In my previous posts, I showed with example how to achieve setter injection by applying “@Autowired” annotation at field level. In this post I will show how to achieve setter injection by applying “@Autowired” annotation directly on…… Continue reading Example of @Autowired (setter injection approach 2)
Example of @Autowired (constructor injection)
In this post under Spring Core, I will show with example, how to use “@Autowired” annotation for constructor injection. In previous post, I showed how to use “@Autowired” annotation for setter injection. We call an approach as setter injection, when Spring framework automatically inject dependency to an object by calling the setter method of the…… Continue reading Example of @Autowired (constructor injection)
Example of @Autowired (setter injection approach 1)
In this post under Spring Core, I will explain with example the purpose and how to use “@Autowired” annotation. Till now in all my previous posts, you have seen how to create a bean. We can create a bean using either “@Bean” or “@Component” annotation. I have also showed you how to wire one “@Bean”…… Continue reading Example of @Autowired (setter injection approach 1)
Using @Profile on @Component annotated beans
In the previous post under Spring Core, I showed how to use “@Profile” annotation with “@Configuration” and “@Bean” annotation. In this post under Spring Core, I will show with example how to use “@Profile” annotation with “@Component” annotation. In previous post I also mentioned that “@Profile” annotation can be used with “@Configuration”, “@Bean”, and “@Component”…… Continue reading Using @Profile on @Component annotated beans
Using @Profile on @Beans annotated beans
In the previous post under Spring Core, I showed how to use “@Profile” annotation with “@Configuration” annotation. In this post under Spring Core, I will show with example how to use “@Profile” annotation with “@Bean” annotation. In previous post I also mentioned that “@Profile” annotation can be used with “@Configuration”, “@Bean”, and “@Component” annotation. The…… Continue reading Using @Profile on @Beans annotated beans
Using @Profile with @Configuration classes
In this post under Spring Core, I will show with example how to use “@Profile” annotation for “@Configuration” annotated classes. In the real world scenario, whenever we develop an application, we develop with a goal that it should perform according to agreed functional requirements, regardless of whether the application is running in production or testing…… Continue reading Using @Profile with @Configuration classes
Changing scopes to @Component annotated class
In this post under Spring Core, I will show with example how to change the scope of class annotated with “@Component” annotation. By default whenever we annotate a class with “@Component” annotation the scope of the bean is set to “singleton”. We can change this by the help of “@Scope” annotation which is also applied…… Continue reading Changing scopes to @Component annotated class
Wiring together @Bean annotated beans using setter approach
In this post under Spring Core, I will explain with example how to wire two beans annotated with @Bean annotation using setter methods. For our example lets take the below two classes. Bean1 package package12; public class Bean1 { private Bean2 bean2; public Bean1() { } public void setBean2(Bean2 bean2) { this.bean2 = bean2; }…… Continue reading Wiring together @Bean annotated beans using setter approach
Changing scopes of @Bean annotated beans
In this post under Spring Core, I will explain with example how to change scopes of Spring beans annotated with “@Bean” annotation. By default the “@Bean” annotated beans have singleton scope. Which means that whenever a dependee bean asks for a reference to dependent bean and the dependent bean scope is “singleton” then Spring makes…… Continue reading Changing scopes of @Bean annotated beans