Pages

Showing posts with label Bean Creation. Show all posts
Showing posts with label Bean Creation. Show all posts

Saturday, April 25, 2020

Building Calculator Application in Spring Boot - @Bean Example



1. Introduction


In this tutorial, We'll learn how to build a simple calculator application using spring boot framework. This is mainly demonstrating to understand @Bean and @Componet annotations usage and how the dependencies are getting injected by the application context.

First, We will see the creation of the calculator interface and its implementation classes.

Next, Creating the Bean with @Bean annotation using the method injection technique.

Finally, Understanding the execution and dependency injections.

Further, You can read examples of bean creation using @Component and @Bean annotations.


Thursday, April 23, 2020

Spring Boot @Component Annotation - Bean Creation Examples

Spring Boot @Component

1. Introduction


In this article, We'll learn how to use @Component annotation in spring or sprig boot application. This looks similar to the use of @Bean annotation and can be used for bean creation.

2. Spring or Spring Boot @Component Annotation


@Component annotation is a class-level annotation that can not be used on the method level. If you define any class with @Component annotation that should be known to the spring application context.
How to make the component class scanned by spring boot is to specify the package of the class to @ComponentScan annotation or use @SpringBootApplication(scanBasePackages = "com.javaprogramto.component").

Spring Boot @Component Annotation - Bean Creation Examples

Tuesday, April 21, 2020

Spring Boot @Bean - Creating Bean In Spring

Spring Boot Bean Creation

1. Introduction


In this tutorial, We'll learn how to Create Bean in Spring and Spring Boot frameworks. We'll look at @Bean annotation along with its scopes and Method Injection examples.

@Bean annotation is introduced in Spring framework to avoid XML level configurations. This can be used in Spring Boot application.

@Bean and @Component are almost are same and used to create the bean but seems like same as produces same as a result.


bean creation in spring boot


2. Spring Boot @Bean Creation Syntax


In Spring Boot, @Bean is a method level annotation and should not be used in any class. And also this annotation tells that it returns a bean that is to be managed by the spring container and registered with spring application context or BeanFactory.


OrderInfo.class
[class OrderInfo{
@Bean
public Customer getCustomer(){
return new Customer();
}
}]

This method returns a bean of the Customer.