--- title: 'SpringBoot ' disqus: hackmd --- ###### tags: `Spring Boot core` `Google Ads` Google Ad Api quick-start === [TOC] ## 筆記目的 了解spring boot 的核心Ioc還有 @Component @Bean 具體請參考: * [Google Ad Api quickstart](https://segmentfault.com/a/1190000014119872) * [stackoverflow @Component versus @Bean](https://stackoverflow.com/questions/10604298/spring-component-versus-bean) ## Spring帮助我们管理Bean分为两个部分,一个是注册Bean,一个装配Bean。 完成这两个动作有三种方式,一种是使用自动配置的方式、一种是使用JavaConfig的方式,一种就是使用XML配置的方式。 在自动配置的方式中,使用@Component去告诉Spring,我是一个bean,你要来管理我,然后使用@AutoWired注解去装配Bean(所谓装配,就是管理对象直接的协作关系)。然后在JavaConfig中,@Configuration其实就是告诉spring,spring容器要怎么配置(怎么去注册bean,怎么去处理bean之间的关系(装配))。那么久很好理解了,@Bean的意思就是,我要获取这个bean的时候,你spring要按照这种方式去帮我获取到这个bean。到了使用xml的方式,也是如此。君不见<bean>标签就是告诉spring怎么获取这个bean,各种<ref>就是手动的配置bean之间的关系。 用@Bean注解的方法:会实例化、配置并初始化一个新的对象,这个对象会由spring IoC 容器管理。
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up