官术网_书友最值得收藏!

Scope of producer methods

By default, producer methods run in the @Dependent scope; this means that each time an instance is requested to be injected within any context, a new instance of the bean will be created. However, you can customize this, by annotating your producer method with a scope annotation, as in the following example:

@SessionScoped 
public class Preferences implements Serializable { 
    ... 
    @Produces 
    @Preferred 
    @RequestScoped 
    public PaymentStrategy getPaymentStrategy() { ... } 
} 

In this example, only one instance of the PaymentStrategy bean will be instantiated per user request.

主站蜘蛛池模板: 博野县| 大悟县| 含山县| 湖南省| 阳山县| 新源县| 贵港市| 清原| 井冈山市| 苗栗县| 海安县| 沈丘县| 海兴县| 四会市| 凉山| 嘉祥县| 日喀则市| 鄂伦春自治旗| 岳池县| 盐津县| 衡阳县| 雷山县| 定结县| 吉木乃县| 巴林左旗| 汾阳市| 沿河| 广州市| 岳阳县| 泊头市| 永昌县| 南部县| 颍上县| 彝良县| 佳木斯市| 商南县| 双辽市| 西昌市| 颍上县| 肇庆市| 金昌市|