@Bean 註解

Spring的註解分爲兩類:.net

1. 註冊bean.對象

@Component , @Repository , @ Controller , @Service , @Configration 這些註解都是把你要實例化的對象轉化成一個Bean,放在IoC容器中.get

2.使用bean.it

把已經在容器中裝配好的Bean拿來用;io

如:@Autowired --> byType,class

        @Resource --> byNAME  的方式獲取Bean;容器

@Bean是放在方法上,使得被注註解的方法,產生一個Bean,而後交給Spring容器。service

相關文章
相關標籤/搜索