9)What is used for @Component & @Bean annotation in Spring Boot? #springboot#java#shorts#interview

preview_player
Показать описание
🌐 Quick Links:

YouTube Shorts Video: Understanding @Component & @Bean Annotations in Spring Boot

1. @Component Annotation:
- Usage: Applied at the class level, indicating to the Spring container that the class should be treated as a Spring bean.
- Example:
```java
@Component
public class DateUtils {
// Class definition
}
```
- Purpose: Typically used for utility classes or components that don't fall into specific categories.

2. @Bean Annotation:
- Example:
```java
@Configuration
public class SecurityConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) {
// Method logic to create and configure the SecurityFilterChain
}
}
```
- Purpose: Used to explicitly declare a bean and provide configuration for that bean. Often employed in scenarios like security configuration.

Tags: #SpringBoot #JavaAnnotations #Programming #DevByteSchool

Stay tuned for more insights and don't forget to like and subscribe! 🚀
Рекомендации по теме
Комментарии
Автор

Configuration also creates a bean right? Or we will use it for inject beans to our app context?

ugveydev