Spring(DI)_02_05

2025. 1. 22. 17:52·Spring, Boot/기초 내용 정리

2025-01-22

 

 

 

 

 

 

 

INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [car.xml]
INFO : org.springframework.context.support.GenericXmlApplicationContext - Refreshing org.springframework.context.support.GenericXmlApplicationContext@32cf48b7: startup date [Wed Jan 22 17:49:41 KST 2025]; root of context hierarchy
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@687e99d8: defining beans [hcar,kcar,scar,car]; root of factory hierarchy
르노삼성자동차 SM7을 운전합니다.
INFO : org.springframework.context.support.GenericXmlApplicationContext - Closing org.springframework.context.support.GenericXmlApplicationContext@32cf48b7: startup date [Wed Jan 22 17:49:41 KST 2025]; root of context hierarchy
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@687e99d8: defining beans [hcar,kcar,scar,car]; root of factory hierarchy

 

package com.spring.di05;

import org.springframework.context.support.GenericXmlApplicationContext;

public class Main {

	public static void main(String[] args) {
		
		GenericXmlApplicationContext container = 
				new GenericXmlApplicationContext("car.xml");
		
		CarImpl car = (CarImpl)container.getBean("car");
		
		car.move();
		
		container.close();
	}
}

 

package com.spring.di05;

public interface Car {

	void drive();
}

 

package com.spring.di05;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class CarImpl {

	private Car car;
	
	// 비지니스 로직
	public void move() {
		this.car.drive();
	}
}

 

package com.spring.di05;

public class SamsungCar implements Car {

	@Override
	public void drive() {
		System.out.println("르노삼성자동차 SM7을 운전합니다.");	
	}
}

 

<?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.xsd">

	<bean id="hcar" class="com.spring.di05.HyundaiCar"/>
	<bean id="kcar" class="com.spring.di05.KiaCar"/>
	<bean id="scar" class="com.spring.di05.SamsungCar"/>
	
	<bean id="car" class="com.spring.di05.CarImpl">
		<property name="car" ref="scar"/>
	</bean>

</beans>

'Spring, Boot > 기초 내용 정리' 카테고리의 다른 글

Spring(MVC)_01_02  (0) 2025.01.22
Spring(MVC)_01_01  (0) 2025.01.22
Spring(DI)_02_04  (0) 2025.01.22
Spring(DI)_02_03  (0) 2025.01.21
Spring(DI)_02_02  (0) 2025.01.21
'Spring, Boot/기초 내용 정리' 카테고리의 다른 글
  • Spring(MVC)_01_02
  • Spring(MVC)_01_01
  • Spring(DI)_02_04
  • Spring(DI)_02_03
mw41817
mw41817
일생의 개발 기록 저장소
  • mw41817
    IT 개발 일지
    mw41817
    • Index (487)
      • HTML (36)
        • 기초 내용 정리 (36)
      • CSS (29)
        • 기초 내용 정리 (29)
      • JavaScript (60)
        • 기초 내용 정리 (60)
      • JQuery (38)
        • 기초 내용 정리 (38)
      • Java (232)
        • 기초 내용 정리 (232)
      • JSP (46)
        • 기초 내용 정리 (46)
      • Spring, Boot (31)
        • 기초 내용 정리 (31)
      • DB (5)
        • Oracle SQL (5)
      • Code WorkBook (6)
        • programmers (6)
        • Baekjoon (0)
      • 기타 (1)
        • 유용한 사이트 (3)
  • 전체
    오늘
    어제
  • 글쓰기 관리
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
    • 카테고리
    • 주인장 GitHub
  • 공지사항

  • 인기 글

  • 태그

    html #코딩 #프로그래밍 #기초
  • 최근 댓글

  • hELLO· Designed By정상우.v4.10.0
mw41817
Spring(DI)_02_05
상단으로

티스토리툴바