您好我的问题是,例如,在applicationcoped bean上生成实例还是applicationcoped吗?它是否需要其类范围或始终依赖?
答案 0 :(得分:2)
规范将生产者方法视为bean(基本上,生产者是如何创建给定bean类型的实例的定义)。因此,规则适用,如果未提供范围,则假定为@Default
。
因此,您的问题的答案是 - 如果没有指定,则生产者范围为@Default
。生产者范围与声明它的bean范围之间没有联系。
@ApplicationScoped
public MyBean {
@Produces //this will produce @Dependent
public Foo produceDependent() {
return new Foo();
}
@Produces
@RequestScoped //produces the scope you define
public Bar produceReqScopedBean() {
return new Bar();
}
}
答案 1 :(得分:1)
取决于
制作@Dependent
@ApplicationScoped
class Bean {
@Produces
public String producesString(){
return "test";
}
}
制作@ApplicationScoped
@ApplicationScoped
class Bean {
@Produces
@ApplicationScoped
public String producesString(){
return "test";
}
}
制作@RequestScoped
@ApplicationScoped
class Bean {
@Produces
@RequestScoped
public String producesString(){
return "test";
}
}