SpringBoot学习之@Configuration注解和@Bean注解

@Configuration

[email protected]注解底层是含有@Component ,所以@Configuration 具有和 @Component 的作用。

[email protected]注解相当于spring的xml配置文件中beans标签,里面可以配置bean。

@Bean

[email protected]注解相当于spring的xml配置文件bean标签,告诉容器注入一个bean。

[email protected]注解的方法上如果没通过bean指定实例名,默认实例名与方法名相同。

[email protected]注解默认为单例模式,可以通过@Scope(“prototype”)设置为多例。

在SpringBoot中注入redisTemplate实例的代码如下:

SpringBoot学习之@Configuration注解和@Bean注解