- 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.
推薦閱讀
- C# 7 and .NET Core Cookbook
- 數據庫程序員面試筆試真題與解析
- Visual C++程序設計學習筆記
- Functional Programming in JavaScript
- Expert Android Programming
- R Data Analysis Cookbook(Second Edition)
- SQL Server與JSP動態網站開發
- Mastering Business Intelligence with MicroStrategy
- ServiceNow:Building Powerful Workflows
- Building Wireless Sensor Networks Using Arduino
- 零代碼實戰:企業級應用搭建與案例詳解
- C++程序設計教程
- QlikView Unlocked
- Clojure High Performance Programming(Second Edition)
- 黑莓(BlackBerry)開發從入門到精通