Spring Bean Scope Annotation: @RequestScope | @SessionScope | @ApplicationScope

https://grokonez.com/spring-framework/spring-bean-scope-annotation-requestscope-sessionscope-applicationscope

Spring Bean Scope Annotation: @RequestScope | @SessionScope | @ApplicationScope

Spring Framework new release 4.3 make some Web Improvements. Among that, it simplifies way to implement Bean Scopes (Request, Session and Application scopes) using Annotation: @RequestScope | @SessionScope | @ApplicationScope. They are only valid in the context of a web-aware Application.

Related Articles:

I. Technology

  • Java 1.8
  • Maven 3.3.9
  • Spring Tool Suite – Version 3.8.1.RELEASE
  • Spring Boot: 1.5.1.RELEASE

    II. Overview

    1. Goal

    To build a simple application using @RequestScope and @SessionScope annotation that shows you the way request, session act and the difference between them. Beside, we also have a lean introduction of @ApplicationScope.

    2. Scope Annotation

    With old approach, we usually annotate the class which bean has scope by:
    
    @Scope(value = [scope], proxyMode = ScopedProxyMode.TARGET_CLASS)
    
  • Proxy Mode TARGET_CLASS: is used for creating AOP proxy of the bean. We must do it when injecting short lived bean scope (request, session...) to long lived bean scope (singleton, prototype) or injecting prototype to singleton scope.
  • We have some type of scope:
  • singleton: only one instance is created (default scope)
  • prototype: new instance is created everytime prototype bean is referenced.
  • request: one instance for a single HTTP request.
  • session: one instance for an HTTP Session
  • globalSession: one instance for a global HTTP Session. Typically only valid when used in a Portlet context.
  • application: Scopes a single bean definition to the lifecycle of a ServletContext (Only valid in the context of a web-aware Spring ApplicationContext).

https://grokonez.com/spring-framework/spring-bean-scope-annotation-requestscope-sessionscope-applicationscope

Spring Bean Scope Annotation: @RequestScope | @SessionScope | @ApplicationScope

Bình luận


White
{{ comment.user.name }}
Bỏ hay Hay
{{comment.like_count}}
Male avatar
{{ comment_error }}
Hủy
   

Hiển thị thử

Chỉnh sửa

Male avatar

loveprogramming

451 bài viết.
79 người follow
Kipalog
{{userFollowed ? 'Following' : 'Follow'}}
Cùng một tác giả
Male avatar
1 0
Tutorial Link: (Link) (Ảnh) Django is a Pythonbased free and opensource web framework that follows the modeltemplateview architectural pattern. A...
loveprogramming viết 6 tháng trước
1 0
Male avatar
1 0
https://loizenai.com/angular11nodejspostgresqlcrudexample/ Angular 11 Node.js PostgreSQL Crud Example (Ảnh) Tutorial: “Angular 11 Node.js Postg...
loveprogramming viết 5 tháng trước
1 0
Male avatar
1 0
Angular Spring Boot jwt Authentication Example Github https://loizenai.com/angularspringbootjwt/ (Ảnh) Tutorial: ” Angular Spring Boot jwt Authe...
loveprogramming viết 5 tháng trước
1 0
Bài viết liên quan
Male avatar
0 0
https://grokonez.com/springframework/injectpropertiesusingvalueannotationsvsenvironmentvsconfigurationproperties Inject Properties using @Value An...
loveprogramming viết 16 ngày trước
0 0
White
8 1
Tổng quan ORM hay Object Relational Mapping: Là một kĩ thuật cho phép bạn truy vấn và thao tác dữ liệu trên database bằng cách sử dụng mô hình hướ...
bqthanh viết 2 năm trước
8 1
{{like_count}}

kipalog

{{ comment_count }}

bình luận

{{liked ? "Đã kipalog" : "Kipalog"}}


Male avatar
{{userFollowed ? 'Following' : 'Follow'}}
451 bài viết.
79 người follow

 Đầu mục bài viết

Vẫn còn nữa! x

Kipalog vẫn còn rất nhiều bài viết hay và chủ đề thú vị chờ bạn khám phá!