Spring 5.0 Cookbook
上QQ阅读APP看书,第一时间看更新

Creating request- and session-scoped beans

Chapter 2, Learning Dependency Injection (DI), discussed a recipe about configuring the lifespan of a bean inside the ApplicationContext container based on fetching or getBean(). These are the long-lived singleton and prototype beans. Now, we will discuss configuring the lifespan or scope of some beans which are bounded within MVC web transactions. This recipe will discuss creating short-lived beans that only last during request dispatch and session handling.