Difference between @Component and @Bean annotation in Spring
source link: http://adnjavainterview.blogspot.com/2023/10/difference-between-component-and-bean-annotation-in-spring.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Sunday 1 October 2023
Difference between @Component and @Bean annotation in Spring
As we discussed about Stereotype annotations in one of the blog post, the @Component annotation is a stereotype annotation in Spring. If you want to convert any java class as a Spring managed bean then to use component annotation. It will scan during the project start up and will create the bean if the component class exist in the component scan package.
@Bean annotation is used to create a bean, this can use along with Configuration annotation. Bean annotation is a method level annotation and name of the method serves as a bean name. Component annotation is a class level annotation.
Example:-@Component public class ProductUtil{ //methods }
@Configuration class HMSAppConfiguration{ @Bean public Customer getCustomer(){ return new Customer(); } }
No comments:
Post a Comment
Recommend
-
43
本文首发于我的个人博客, Bean装配,从Spring到Spring Boot ,欢迎访问! 本文旨在厘清从Spring 到Spring Boot过程中,Bean装配的...
-
27
学习spring源码主框架,从源码角度开发学习Spring bean的生命周期。 spring创建bean方法 org.springframework.beans.factory.support.AbstractBeanFactory#getBean(java.lang.String, java.lang.Class )
-
18
在Spring中,那些由IoC容器所管理的对象被称之为bean。而一个bean的定义,其实只是一个“蓝图”,指导着Spring如何去创建这样一个bean。而在这个蓝图中,有一个属性叫做“作用域”,它规定了这个bean的可见范围。这里我们看一下Spring的bean都...
-
19
2. Bean的装配 Spring容器负责创建应用程序中的bean,并通过DI来协调对象之间的关系。Spring提供了三种主要的装配机制: ...
-
14
java-version.com: What's new in Java 16? 15? Keep up to date! Use Groovy has Spring bean in a JSF web application
-
4
Singleton and Prototype Bean Scopes in Java SpringSkip to content
-
3
Difference between ApplicationContext and BeanFactory in Spring frameworkSkip to content...
-
8
Difference Between React Component Tests and React Hook Tests
-
5
Difference between @SpringBootTest vs @WebMVCTest in Spr...
-
8
Difference Between @Resource, @Autowired and @Inject in Spring Injection In this post, we will learn the difference between Resource, Autowired and Inject annotation. All these annotations are used to inject the bean dependen...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK