πΒ λΉ μ€μ½ν
λΉ μ€μ½νλ?
β μ§κΈκΉμ§ μ°λ¦¬λ μ€νλ§ λΉμ΄ μ€νλ§ μ»¨ν
μ΄λμ μμκ³Ό ν¨κ» μμ±λμ΄μ μ€νλ§ μ»¨ν
μ΄λκ° μ’
λ£λ λ κΉμ§ μ μ§λλ€κ³ νμ΅νλ€.
- μ΄κ²μ μ€νλ§ λΉμ΄ κΈ°λ³Έμ μΌλ‘ μ±κΈν€ μ€μ½νλ‘ μμ±λκΈ° λλ¬Έμ΄λ€.
- μ€μ½νλ λ²μ κ·Έλλ‘ λΉμ΄ μ‘΄μ¬ν μ μλ λ²μλ₯Ό λ»νλ€.
μ€νλ§μ λ€μκ³Ό κ°μ λ€μν μ€μ½νλ₯Ό μ§μνλ€.
- μ±κΈν€ : κΈ°λ³Έ μ€μ½ν, μ€νλ§ μ»¨ν
μ΄λμ μμκ³Ό μ’
λ£κΉμ§ μ μ§λλ κ°μ₯ λμ λ²μμ μ€μ½νμ΄λ€.
- νλ‘ν νμ
: μ€νλ§ μ»¨ν
μ΄λλ νλ‘ν νμ
λΉμ μμ±κ³Ό μμ‘΄κ΄κ³ μ£Όμ
κΉμ§λ§ κ΄μ¬νκ³ λλ κ΄λ¦¬νμ§ μλ
λ§€μ° μ§§μ λ²μμ μ€μ½νμ΄λ€.
- μΉ κ΄λ ¨ μ€μ½ν
- request : μΉ μμ²μ΄ λ€μ΄μ€κ³ λκ°λ κΉμ§ μ μ§λλ μ€μ½νμ΄λ€.
- session : μΉ μΈμ
μ΄ μμ±λκ³ μ’
λ£λ λ κΉμ§ μ μ§λλ μ€μ½νμ΄λ€.
- application : μΉμ μλΈλ¦Ώ 컨ν
μ€νΈμ κ°μ λ²μλ‘ μ μ§λλ μ€μ½νμ΄λ€.
β λΉ μ€μ½νλ λ€μκ³Ό κ°μ΄ μ§μ ν μ μλ€.
μ»΄ν¬λνΈ μ€μΊ μλ λ±λ‘
@Scope("prototype")
@Component
public class HelloBean {}
μλ λ±λ‘
@Scope("prototype")
@Bean
PrototypeBean HelloBean() {
return new HelloBean();
}