c. Bean Definition - kimxavi/spring_tutorial GitHub Wiki

Bean은 μΈμŠ€ν„΄μŠ€ν™”λ˜κ³ , 쑰립되고, Spring IoC container에 κ΄€λ¦¬λ˜λŠ” 객체이닀. 이 bean듀을 μ»¨ν…Œμ΄λ„ˆμ— κ³΅κΈ‰ν•˜λŠ” μ„€μ • 메타데이터 예λ₯Ό λ“€μ–΄, κ³Ό 같은 XML 폼에 μ˜ν•΄ μƒμ„±λœλ‹€. bean μ •μ˜λŠ” μ„€μ • 메타데이터에 정보λ₯Ό ν¬ν•¨ν•œλ‹€.

  • bean이 μ–΄λ–»κ²Œ μƒμ„±λ˜λŠ”μ§€
  • bean의 라이프 사이클 상세
  • bean의 μ˜μ‘΄μ„±(dependencies)

Properties

  • class : 이 속성은 μ˜λ¬΄μ μ΄λ‹€. bean의 생성에 μ‚¬μš©λ  클래슀λ₯Ό λͺ…μ‹œν•œλ‹€.
  • name : bean 의 고유의 identifier 이닀. XML μ„€μ • λ©”νƒ€λ°μ΄ν„°μ—μ„œ id 그리고/λ˜λŠ” name μ†μ„±μœΌλ‘œ bean을 λͺ…μ‹œν•œλ‹€.
  • scope : 이 속성을 μƒμ„±λœ 객체의 λ²”μœ„λ₯Ό μ§€μ •ν•œλ‹€.
  • constructor-arg, properties, autowiring mode : 이것은 μ˜μ‘΄μ„± μ£Όμž…μ— μ‚¬μš©λœλ‹€.
  • lazy-initialization mode : lazy-initialized bean 은 μ‹œμž‘ν•  λ•Œ 보닀, 첫 μš”μ²­ λ•Œ bean μΈμŠ€ν„΄μŠ€κ°€ μƒμ„±λ˜λ„λ‘ IoC μ»¨ν…Œμ΄λ„ˆμ— μš”μ²­ν•©λ‹ˆλ‹€.
  • initialization method : bean에 ν•„μš”ν•œ λͺ¨λ“  속성듀이 μ»¨ν…Œμ΄λ„ˆμ— μ˜ν•΄ μ„ΈνŒ…λœ 후에 λΆˆλŸ¬μ§€λŠ” 콜백
  • destruction method : μ»¨ν…Œμ΄λ„ˆκ°€ bean이 μ†Œλ©Έλ˜μ–΄μ§€λŠ” 것을 포함할 λ•Œ λΆˆλŸ¬μ§€λŠ” 콜백

Spring Configuration Metadata

  • XML 기반의 μ„€μ • 파일
  • μ–΄λ…Έν…Œμ΄μ…˜ 기반의 μ„€μ •
  • μžλ°” 기반의 μ„€μ •

XML 기반 μ„€μ • 파일 μ˜ˆμ‹œ

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

   <!-- A simple bean definition -->
   <bean id="..." class="...">
       <!-- collaborators and configuration for this bean go here -->
   </bean>

   <!-- A bean definition with lazy init set on -->
   <bean id="..." class="..." lazy-init="true">
       <!-- collaborators and configuration for this bean go here -->
   </bean>

   <!-- A bean definition with initialization method -->
   <bean id="..." class="..." init-method="...">
       <!-- collaborators and configuration for this bean go here -->
   </bean>

   <!-- A bean definition with destruction method -->
   <bean id="..." class="..." destroy-method="...">
       <!-- collaborators and configuration for this bean go here -->
   </bean>

   <!-- more bean definitions go here -->

</beans>
⚠️ **GitHub.com Fallback** ⚠️