Reputation: 139
Hello my question is does a produce for example on a applicationscoped bean produces instances also applicationscoped? Does it take its class scope or is always dependent?
Upvotes: 2
Views: 693
Reputation: 6753
The specification treats producer methods as beans (basically, producer is a definiton of how you create an instance of given bean type). Therefore a rule applies, that if no scope is provided, @Default
is assumed.
Hence the answer to your question is - the producer scope is @Default
if none is specified. There is no link between producer scope and the scope of the bean on which it is declared.
@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();
}
}
Upvotes: 3
Reputation: 2268
It depends on
Produces @Dependent
@ApplicationScoped
class Bean {
@Produces
public String producesString(){
return "test";
}
}
Produces @ApplicationScoped
@ApplicationScoped
class Bean {
@Produces
@ApplicationScoped
public String producesString(){
return "test";
}
}
Produces @RequestScoped
@ApplicationScoped
class Bean {
@Produces
@RequestScoped
public String producesString(){
return "test";
}
}
Upvotes: 1