小编use*_*232的帖子

为singleton bean创建了多少个引用会话bean/prototype bean的实例

我怀疑使用Spring时将在下面提到的场景中创建的实例数量:

bean配置是这样的

  <bean id="a" class="A">
    <property name="b" ref="b"/>
    </bean>

<bean id="b" class="B" scope="session"/> or

 <bean id="b" class="B" scope="prototype"/>
Run Code Online (Sandbox Code Playgroud)

默认情况下,bean"a"具有singleton scope.因此,有一个单例bean,它引用了一个具有会话范围或原型范围的bean.

在这种情况下,如果同时有2个应用程序请求,那么将创建多少个A实例以及将创建多少个B实例?

如果有人可以解释这是如何工作的,那将会有很大的帮助吗?

谢谢,Divya

spring instance

26
推荐指数
1
解决办法
4万
查看次数

Generics-Type参数如何工作?

我是java中Generics的新手.我尝试过以下方法:

Entity class:
public class Box<T> {
    private List<T> boxList;

    public List<T> getBoxList() {
        if (this.boxList == null)
            this.boxList = new ArrayList<T>();

        return this.boxList;
    }

    public void setBoxList(List<T> boxList) {
        this.boxList = boxList;
    }

}

Test class:

public class Client {
public static void main(String[] args) {
    Box box = new Box();
    box.getBoxList().add(1);
    box.getBoxList().add("one");
System.out.println(box.getBoxList());

Box boxInt=new Box<Integer>();
boxInt.getBoxList().add("apple");
System.out.println(boxInt.getBoxList());

}
}
Run Code Online (Sandbox Code Playgroud)

虽然我的boxInt是Integer类型,但BoxList列表仍然接受"apple".我希望它在编译时抛出一个错误.任何有关如何工作的帮助将非常感谢.

谢谢,Divya

java generics

1
推荐指数
1
解决办法
52
查看次数

标签 统计

generics ×1

instance ×1

java ×1

spring ×1