길민호(ethan.mino)
코딩수첩
길민호(ethan.mino)
전체 방문자
오늘
어제
  • 분류 전체보기 (215)
    • Computer Science (0)
    • Web (6)
      • CSS (0)
      • HTML (0)
    • Node.js (0)
    • Javascript (2)
    • Java (46)
      • Spring (27)
      • Jsp (0)
    • C\C++ (2)
    • Programming (0)
    • AI (0)
    • Database (7)
    • Git (5)
    • Algorithm (119)
      • Stack (0)
      • Queue (0)
      • Linked List (0)
      • Sort (0)
      • Simulation (27)
      • Recursion (0)
      • Backtracking (4)
      • Two Pointer (3)
      • Dynamic Programming (19)
      • Greedy (10)
      • Graph (3)
      • Dijkstra (1)
      • BFS\DFS (8)
      • Floyd (1)
      • MST (4)
      • Tree (4)
      • Binary Search (8)
      • Binary Search Tree (4)
    • IntelliJ (4)
    • Vscode (0)
    • Operating System (0)
    • 후기 (3)
    • 성장일지 (13)
    • 스터디 (7)
    • 설치 (1)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • ㅡ

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
길민호(ethan.mino)

코딩수첩

Java/Spring

Spring 싱글톤(Singleton) Scope

2020. 6. 28. 19:34

싱글톤이란 메모리에 하나만 생성한다는 것이고,

Spring은 빈을 생성할 때 기본적으로 싱글톤(Singleton) 객체로 생성한다.

메모리에 하나만 생성되었을 경우, 해당 객체를 동시에 이용한다면 어떤 문제가 발생하는가?

이런 문제를 해결하려면 어떻게 해야할까?

  • 여러명이 싱글톤 객체를 동시에 사용하는 경우, 데이터가 원치 않은 방향으로 변조되어 본래의 의미를 잃어버리게 되어 문제가 발생한다.
  • xml파일에 bean태그를 입력할 때, scope속성을 줄 수 있다. scope속성을 명시하지 않은 경우, singleton 타입으로 지정되며, scope속성을prototype으로 지정하면, getBean메소드를 통해, 해당 객체를 요청할 때마다 새로운 객체를 생성, 반환하게 된다. 따라서, 싱글톤 객체의 문제를 해결할 수 있다.

전자정부프레임워크 wiki

global session  하나의 Bean 정의에 대해서 하나의 global HTTP Session의 생명주기 안에 단 하나의 객체만 존재한다. 
일반적으로 portlet context 안에서 유효하다. Web-aware Spring ApplicationContext 안에서만 유효하다.
prototype 하나의 Bean 정의에 대해서 다수의 객체가 존재할 수 있다.
request 하나의 Bean 정의에 대해서 하나의 HTTP request의 생명주기 안에 단 하나의 객체만 존재한다; 
즉, 각각의 HTTP request는 자신만의 객체를 가진다. Web-aware Spring ApplicationContext 안에서만 유효하다.
session 하나의 Bean 정의에 대해서 하나의 HTTP Session의 생명주기 안에 단 하나의 객체만 존재한다. Web-aware Spring ApplicationContext 안에서만 유효하다.
singleton  하나의 Bean 정의에 대해서 Spring IoC Container 내에 단 하나의 객체만 존재한다.

 

스프링 레퍼런스

singleton (Default) Scopes a single bean definition to a single object instance per Spring IoC container.
prototype Scopes a single bean definition to any number of object instances.
request Scopes a single bean definition to the lifecycle of a single HTTP request; that is, each HTTP request has its own instance of a bean created off the back of a single bean definition. Only valid in the context of a web-aware Spring ApplicationContext.
session Scopes a single bean definition to the lifecycle of an HTTP Session. Only valid in the context of a web-aware Spring ApplicationContext.
global session Scopes a single bean definition to the lifecycle of a global HTTP Session. Typically only valid when used in a portlet context. Only valid in the context of a web-aware Spring ApplicationContext.
application Scopes a single bean definition to the lifecycle of a ServletContext. Only valid in the context of a web-aware Spring ApplicationContext.

 

 

참조 URL

  • https://gmlwjd9405.github.io/2018/11/10/spring-beans.html,
  • http://https://www.edwith.org/boostcourse-web/lecture/20657/
  • https://www.slipp.net/wiki/pages/viewpage.action?pageId=25528177

'Java > Spring' 카테고리의 다른 글

DispatcherServlet  (0) 2020.06.28
Spring MVC 기본 동작 흐름  (0) 2020.06.28
DB에 Insert 할 때, SimpleJdbcInsert을 사용하는 이유는?  (0) 2020.06.28
Spring MVC란?  (0) 2020.06.28
Spring Tip!  (0) 2020.06.28
    'Java/Spring' 카테고리의 다른 글
    • DispatcherServlet
    • Spring MVC 기본 동작 흐름
    • DB에 Insert 할 때, SimpleJdbcInsert을 사용하는 이유는?
    • Spring MVC란?
    길민호(ethan.mino)
    길민호(ethan.mino)
    💻 호기심 많은 서버 개발자 길민호입니다.

    티스토리툴바