Bean的作用域:

支持四种配置,分别是singleton,prototype,request,session。

Spring(十):Spring配置Bean(三)Bean的作用域、使用外部属性文件

singleton

默认情况下在spring confinguration xml文件中的一个bean配置中,如果不指定scope属性,则这个scope默认值为singleton。

如何把一个bean配置为scope='singleton':

Spring(十):Spring配置Bean(三)Bean的作用域、使用外部属性文件

Person.java

package com.dx.beans.scope;

public class Person {
    private int id;
    private String name;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Person() {
        System.out.println("Person's Constructor...");
    }

    @Override
    public String toString() {
        return "Person [>;
    }
}
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-14
  • 2021-12-20
  • 2021-11-25
  • 2022-01-15
  • 2021-10-14
猜你喜欢
  • 2021-12-21
  • 2021-11-14
  • 2021-10-19
  • 2021-08-16
  • 2021-10-24
  • 2022-01-16
相关资源
相似解决方案