作用
设置 bean 的作用域
参数
prototype:多例,懒加载,在获取 bean 时,创建实例,获取几次就创建几个实例singleton:默认单例,饿汉式,在 IOC 容器创建时,创建实例request:同一次请求创建一个实例session:同一个 session 创建一个实例
案例代码
@Scope("prototype")
@Bean("user")
public User user01() {
return new User("tom", "123");
}参考链接