import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.ComponentScans;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.Scope;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import com.ceshi.bean.PersonBean;
import com.ceshi.demo.MyFilterType;
//配置类==配置文件(xml)
@Configuration //告诉Spring这个一个配制类
public class BeanConfig2 {
/**
* Specifies the name of the scope to use for the annotated component/bean.
* <p>Defaults to an empty string ({@code ""}) which implies
* {@link ConfigurableBeanFactory#SCOPE_SINGLETON SCOPE_SINGLETON}.
* @since 4.2
* @see ConfigurableBeanFactory#SCOPE_PROTOTYPE
* @see ConfigurableBeanFactory#SCOPE_SINGLETON
* @see org.springframework.web.context.WebApplicationContext#SCOPE_REQUEST
* @see org.springframework.web.context.WebApplicationContext#SCOPE_SESSION
* @see #value
* singleton:单例
* prototype:多实例,IOC容器不会在启动的时候创建bean,而是在每次获取的时候创建bean
* request:同一次请求创建一个实例
* session:同一个session会话创建一个实例
*
*/
@Scope("prototype")
//给容器注册一个Bean,类型class:默认为返回值的类型,标识id:默认为方法名
@Bean("person")
public PersonBean personBean(){
return new PersonBean("lishi","20");
}
}
注意:IOC容器在创建bean的时候不会在启动的时候创建多实例bean,只会在使用的时候创建。
6万+

被折叠的 条评论
为什么被折叠?



