- 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.
推薦閱讀
- 數據庫系統原理及MySQL應用教程(第2版)
- Designing Machine Learning Systems with Python
- Learning Cython Programming(Second Edition)
- C語言程序設計(第2版)
- RTC程序設計:實時音視頻權威指南
- C語言程序設計實踐教程
- Easy Web Development with WaveMaker
- Magento 1.8 Development Cookbook
- Python深度學習:基于TensorFlow
- Java系統化項目開發教程
- ElasticSearch Cookbook(Second Edition)
- C#開發案例精粹
- 現代C++編程實戰:132個核心技巧示例(原書第2版)
- Learning JavaScript Data Structures and Algorithms(Second Edition)
- GitHub入門與實踐