- Developing Middleware in Java EE 8
- Abdalla Mahmoud
- 91字
- 2021-07-23 19:24:34
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.
推薦閱讀
- LaTeX Cookbook
- Flask Web開發(fā)入門、進(jìn)階與實戰(zhàn)
- Swift 3 New Features
- 零基礎(chǔ)學(xué)Python數(shù)據(jù)分析(升級版)
- Python貝葉斯分析(第2版)
- D3.js 4.x Data Visualization(Third Edition)
- JavaScript程序設(shè)計:基礎(chǔ)·PHP·XML
- 從Excel到Python數(shù)據(jù)分析:Pandas、xlwings、openpyxl、Matplotlib的交互與應(yīng)用
- Python開發(fā)基礎(chǔ)
- Clojure High Performance Programming(Second Edition)
- 數(shù)據(jù)科學(xué)中的實用統(tǒng)計學(xué)(第2版)
- WCF技術(shù)剖析(卷1)
- 少兒編程輕松學(xué)(全2冊)
- Java服務(wù)端研發(fā)知識圖譜
- Learning TypeScript