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

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.

主站蜘蛛池模板: 定州市| 西宁市| 栾川县| 伊宁县| 和田市| 临安市| 全州县| 韶山市| 繁昌县| 合水县| 綦江县| 池州市| 安阳市| 芮城县| 金沙县| 江永县| 敖汉旗| 凤山县| 苏州市| 海淀区| 庄河市| 林西县| 邢台县| 永泰县| 华坪县| 五台县| 浏阳市| 阿坝县| 德庆县| 安顺市| 屯门区| 宾川县| 增城市| 浦北县| 德格县| 天长市| 宝兴县| 钟祥市| 南华县| 博爱县| 岑溪市|