SlideShare une entreprise Scribd logo
1  sur  18
Spring Framework
Spring DI
(Dependency Injection_4)
Spring Framework_Spring Ioc & DI
Spring IoC & DI
5. Spring DI
10) 스프링에서 XML 설정 파일의 분리
XML 설정파일을 여러 개로 분리할 수 있으며 이 경우 ref bean 태그를 사용하여 자바 빈을
로딩하면된다. ApplicationContext를 생성할 때 여러 XML 파일명을 문자열 배열로 넣어주면 된다.
package ojc.spring.twoxml;
public interface Dog {
public void jitda();
}
[Dog.java]
Spring Framework_Spring Ioc & DI
package ojc.spring.twoxml;
import org.springframework.stereotype.Component;
public class Pudle implements Dog {
public void jitda() {
System.out.println("푸들푸들~");
}
}
[Pudle.java]
package ojc.spring.twoxml;
import org.springframework.stereotype.Component;
public class Jindo implements Dog{
public void jitda() {
System.out.println("진도진도~");
}
}
[Jindo.java]
Spring Framework_Spring Ioc & DI
package ojc.spring.twoxml;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
public class DogManager {
private Pudle pudle;
private Jindo jindo;
public void setPudle(Pudle pudle) {
this.pudle = pudle;
}
public void setJindo(Jindo jindo) {
this.jindo = jindo;
}
public void walwal() {
this.jindo.jitda();
this.pudle.jitda();
}
}
[DogManager.java]
Spring Framework_Spring Ioc & DI
package ojc.spring.twoxml;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class DogApp {
public static void main(String[] args) {
ApplicationContext context =
new ClassPathXmlApplicationContext(new String[] {"applicationContext.xml", "dog.xml"});
DogManager dManager = (DogManager) context.getBean("dogManager");
dManager.walwal();
}
}
[DogApp.java]
Spring Framework_Spring Ioc & DI
<?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-4.2.xsd">
<bean id="dogManager" class="ojc.spring.twoxml.DogManager">
<property name="pudle">
<ref bean="pudle"></ref>
</property>
<propertyname="jindo">
<ref bean="jindo"></ref>
</property>
</bean>
</beans>
[src/main/resources/applicationContext.xml]
Spring Framework_Spring Ioc & DI
<?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-4.2.xsd">
<bean id="pudle" class="ojc.spring.twoxml.Pudle"/>
<bean id="jindo" class="ojc.spring.twoxml.Jindo"/>
</beans>
[src/main/resources/dog.xml]
진도진도~
푸들푸들~
[결과]
Spring Framework_Spring Ioc & DI
11) ApplicationContext의 분리(부모, 자식)
한 컨텍스는 다른 컨텍스트의 부모가 될 수 있다. 자식 컨텍스에 있는 빈이 부모 컨텍스트에 있는
빈 참조 가능한 데 스프링은 ApplicationContext 중첩 기능을 제공함으로서 설정을 여러 파일로 나눌 수 있게
해준다. 자식 컨텍스트에서 부모컨텍스트의 빈을 참조하는 방식은 동일하다.
단, 이름이 같은 것이 있다면 ref 태그에서 parent 속성을 사용하면 된다.
<?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-4.2.xsd">
<bean id="parent1" class="java.lang.String">
<constructor-arg>
<value>parent bean 1</value>
</constructor-arg>
</bean>
<bean id="parent2" class="java.lang.String">
<constructor-arg>
<value>parent bean 2</value>
</constructor-arg>
</bean>
</beans>
[parent.java]
Spring Framework_Spring Ioc & DI
<?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-4.2.xsd">
<bean id="target1" class="onj.context.overlap.Onj">
<property name="val1">
<ref bean="parent1"/>
</property>
</bean>
<bean id="target2" class="onj.context.overlap.Onj">
<property name="val2">
<ref parent="parent2"/> <!–부모context에서 parent2라는 id,name을 검색
</property>
</bean>
<bean id="parent2" class="java.lang.String">
<constructor-arg>
<value>child bean 2</value>
</constructor-arg>
</bean>
</beans>
[child.xml]
Spring Framework_Spring Ioc & DI
package onj.context.overlap;
public class Onj {
private String val1;
private String val2;
public String getVal1() {
return val1;
}
public void setVal1(String val1) {
this.val1 = val1;
}
public String getVal2() {
return val2;
}
public void setVal2(String val2) {
this.val2 = val2;
}
}
[Onj.java]
Spring Framework_Spring Ioc & DI
package onj.context.overlap;
import org.springframework.context.support.GenericXmlApplicationContext;
public class ContextOverlapExam {
public static void main(String[] args) {
GenericXmlApplicationContext parent= new GenericXmlApplicationContext();
parent.load("classpath:parent.xml");
parent.refresh();
GenericXmlApplicationContext child = new GenericXmlApplicationContext();
child.load("classpath:child.xml");
child.setParent(parent);
child.refresh();
Onj target1 = (Onj) child.getBean("target1");
Onj target2 = (Onj) child.getBean("target2");
String target3 = (String) child.getBean("parent2");
System.out.println(target1.getVal1());
System.out.println(target2.getVal2());
System.out.println(target3);
}
}
[ContextOverlapExam.java]
Spring Framework_Spring Ioc & DI
12) 컬렉션 주입, XML 방식
빈에서 개별 빈이나 값이 아닌 객체의 컬렉션에 접근해야 되는 경우가있는데 <list>, <map>, <set>, <prop>를
사용한다. 자바에서 Properties 클래스는property 값으로 String을 지원하므로 String만 넘길 수 있다.
<?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-4.2.xsd">
<bean id="onj" name="onjName" class="onj.injection.collection.Onj"/>
<bean id="sample" class="onj.injection.collection.CollectionExam">
<property name="map">
<map>
<entry key="someValue">
<value>hello map...</value>
</entry>
<entry key="someBean">
<ref bean="onj"/>
</entry>
</map>
[app-context5.xml]
Spring Framework_Spring Ioc & DI
</property>
<property name="set">
<set>
<value>hello list...</value>
<ref bean="onj"/>
</set>
</property>
<property name="props">
<props>
<prop key="firstName">Jong Cheol</prop>
<prop key="lastName">Lee</prop>
</props>
</property>
</bean>
</beans>
[app-context5.xml]
Spring Framework_Spring Ioc & DI
public void display() {
for(Map.Entry<String, Object> entry:map.entrySet()) {
System.out.println("Key: " + entry.getKey() + "-" + entry.getValue());
}
for(Map.Entry<Object, Object> entry : props.entrySet()) {
System.out.println("key : " + entry.getKey() + "-" + entry.getValue() );
}
for(Object obj : set) {
System.out.println("value : " + obj);
}
}
public static void main(String[] args) {
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
ctx.load("classpath:app-context5.xml");
ctx.refresh();
CollectionExam col = (CollectionExam)ctx.getBean("sample“)
col.display();
}
[CollectionExam.java]
Spring Framework_Spring Ioc & DI
12) 컬렉션 주입, 어노테이션 방식
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-4.2.xsd">
<context:annotation-config/>
<context:component-scan base-package="onj.collection.annotation" />
<bean id="onj" name="onjName" class="onj.collection.annotation.Onj"/>
<util:map id="map" map-class="java.util.HashMap">
<entry key="someValue">
<value>hello... map</value>
</entry>
[app-context6.xml]
Spring Framework_Spring Ioc & DI
<entry key="someBean">
<ref ben="onj"/>
</entry>
</util:map>
<util:properties id="props">
<prop key="firstName">Jong Cheol</prop>
<prop key="lastName">Lee</prop>
</util:properties>
<util:set id="set">
<value>hello.... set</value>
<ref bean="onj"/>
</util:set>
</beans>
[app-context6.xml]
Spring Framework_Spring Ioc & DI
package onj.collection.annotation;
import org.springframework.stereotype.Service;
@Service("onj")
public class Onj {
public String toString() {
return "my name is OnJ";
}
}
[Onj.java]
Spring Framework_Spring Ioc & DI
…
…
@Service("sample")
public class CollectionAnnotationExam {
@Resource(name="map")
private Map<String, Object> map ;
@Resource(name="props")
private Properties props;
@Resource(name="set")
private Set<Object> set;
…
…
…
[CollectionAnnotationExam.java]

Contenu connexe

Tendances

Spring framework
Spring frameworkSpring framework
Spring framework
Ajit Koti
 
Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6
Ray Ploski
 

Tendances (20)

Dependency injection with koin
Dependency injection with koinDependency injection with koin
Dependency injection with koin
 
Spring IOC advantages and developing spring application sample
Spring IOC advantages and developing spring application sample Spring IOC advantages and developing spring application sample
Spring IOC advantages and developing spring application sample
 
Dependency Injection with CDI in 15 minutes
Dependency Injection with CDI in 15 minutesDependency Injection with CDI in 15 minutes
Dependency Injection with CDI in 15 minutes
 
Kotlinでテストコードを書く
Kotlinでテストコードを書くKotlinでテストコードを書く
Kotlinでテストコードを書く
 
Getting start Java EE Action-Based MVC with Thymeleaf
Getting start Java EE Action-Based MVC with ThymeleafGetting start Java EE Action-Based MVC with Thymeleaf
Getting start Java EE Action-Based MVC with Thymeleaf
 
Spring boot
Spring bootSpring boot
Spring boot
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
RSpec 3.0: Under the Covers
RSpec 3.0: Under the CoversRSpec 3.0: Under the Covers
RSpec 3.0: Under the Covers
 
Spring
SpringSpring
Spring
 
Spring talk111204
Spring talk111204Spring talk111204
Spring talk111204
 
Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6
 
Kotlin is charming; The reasons Java engineers should start Kotlin.
Kotlin is charming; The reasons Java engineers should start Kotlin.Kotlin is charming; The reasons Java engineers should start Kotlin.
Kotlin is charming; The reasons Java engineers should start Kotlin.
 
Testing untestable code - DPC10
Testing untestable code - DPC10Testing untestable code - DPC10
Testing untestable code - DPC10
 
Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101
 
When Enterprise Java Micro Profile meets Angular
When Enterprise Java Micro Profile meets AngularWhen Enterprise Java Micro Profile meets Angular
When Enterprise Java Micro Profile meets Angular
 
CDI: How do I ?
CDI: How do I ?CDI: How do I ?
CDI: How do I ?
 
Java Enterprise Edition
Java Enterprise EditionJava Enterprise Edition
Java Enterprise Edition
 
GeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassleGeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassle
 
Why Kotlin - Apalon Kotlin Sprint Part 1
Why Kotlin - Apalon Kotlin Sprint Part 1Why Kotlin - Apalon Kotlin Sprint Part 1
Why Kotlin - Apalon Kotlin Sprint Part 1
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 

Similaire à 9.Spring DI_4

Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
Alexey Buzdin
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
C.T.Co
 
Soundreader.classpathSoundreader.project Soundre.docx
Soundreader.classpathSoundreader.project  Soundre.docxSoundreader.classpathSoundreader.project  Soundre.docx
Soundreader.classpathSoundreader.project Soundre.docx
whitneyleman54422
 
Python mu Java mı?
Python mu Java mı?Python mu Java mı?
Python mu Java mı?
aerkanc
 
SqlDbConnection.jarMETA-INFMANIFEST.MFManifest-Version.docx
SqlDbConnection.jarMETA-INFMANIFEST.MFManifest-Version.docxSqlDbConnection.jarMETA-INFMANIFEST.MFManifest-Version.docx
SqlDbConnection.jarMETA-INFMANIFEST.MFManifest-Version.docx
whitneyleman54422
 
Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01
Tino Isnich
 
Java Programming Must implement a storage manager that main.pdf
Java Programming Must implement a storage manager that main.pdfJava Programming Must implement a storage manager that main.pdf
Java Programming Must implement a storage manager that main.pdf
adinathassociates
 

Similaire à 9.Spring DI_4 (20)

#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Python mu Java mı?
Python mu Java mı?Python mu Java mı?
Python mu Java mı?
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Soundreader.classpathSoundreader.project Soundre.docx
Soundreader.classpathSoundreader.project  Soundre.docxSoundreader.classpathSoundreader.project  Soundre.docx
Soundreader.classpathSoundreader.project Soundre.docx
 
Python mu Java mı?
Python mu Java mı?Python mu Java mı?
Python mu Java mı?
 
Spring
SpringSpring
Spring
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 
Androidaop 170105090257
Androidaop 170105090257Androidaop 170105090257
Androidaop 170105090257
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Java Serialization
Java SerializationJava Serialization
Java Serialization
 
SqlDbConnection.jarMETA-INFMANIFEST.MFManifest-Version.docx
SqlDbConnection.jarMETA-INFMANIFEST.MFManifest-Version.docxSqlDbConnection.jarMETA-INFMANIFEST.MFManifest-Version.docx
SqlDbConnection.jarMETA-INFMANIFEST.MFManifest-Version.docx
 
Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01
 
Spring hibernate jsf_primefaces_intergration
Spring hibernate jsf_primefaces_intergrationSpring hibernate jsf_primefaces_intergration
Spring hibernate jsf_primefaces_intergration
 
Making the most of your gradle build - Gr8Conf 2017
Making the most of your gradle build - Gr8Conf 2017Making the most of your gradle build - Gr8Conf 2017
Making the most of your gradle build - Gr8Conf 2017
 
Nice to meet Kotlin
Nice to meet KotlinNice to meet Kotlin
Nice to meet Kotlin
 
Making the most of your gradle build - Greach 2017
Making the most of your gradle build - Greach 2017Making the most of your gradle build - Greach 2017
Making the most of your gradle build - Greach 2017
 
Java Programming Must implement a storage manager that main.pdf
Java Programming Must implement a storage manager that main.pdfJava Programming Must implement a storage manager that main.pdf
Java Programming Must implement a storage manager that main.pdf
 

Plus de 탑크리에듀(구로디지털단지역3번출구 2분거리)

(스프링프레임워크 강좌)스프링부트개요 및 HelloWorld 따라하기
(스프링프레임워크 강좌)스프링부트개요 및 HelloWorld 따라하기(스프링프레임워크 강좌)스프링부트개요 및 HelloWorld 따라하기
(스프링프레임워크 강좌)스프링부트개요 및 HelloWorld 따라하기
탑크리에듀(구로디지털단지역3번출구 2분거리)
 
[아이오닉학원]아이오닉 하이브리드 앱 개발 과정(아이오닉2로 동적 모바일 앱 만들기)
[아이오닉학원]아이오닉 하이브리드 앱 개발 과정(아이오닉2로 동적 모바일 앱 만들기)[아이오닉학원]아이오닉 하이브리드 앱 개발 과정(아이오닉2로 동적 모바일 앱 만들기)
[아이오닉학원]아이오닉 하이브리드 앱 개발 과정(아이오닉2로 동적 모바일 앱 만들기)
탑크리에듀(구로디지털단지역3번출구 2분거리)
 
[뷰제이에스학원]뷰제이에스(Vue.js) 프로그래밍 입문(프로그레시브 자바스크립트 프레임워크)
[뷰제이에스학원]뷰제이에스(Vue.js) 프로그래밍 입문(프로그레시브 자바스크립트 프레임워크)[뷰제이에스학원]뷰제이에스(Vue.js) 프로그래밍 입문(프로그레시브 자바스크립트 프레임워크)
[뷰제이에스학원]뷰제이에스(Vue.js) 프로그래밍 입문(프로그레시브 자바스크립트 프레임워크)
탑크리에듀(구로디지털단지역3번출구 2분거리)
 
[씨샵학원/씨샵교육]C#, 윈폼, 네트워크, ado.net 실무프로젝트 과정
[씨샵학원/씨샵교육]C#, 윈폼, 네트워크, ado.net 실무프로젝트 과정[씨샵학원/씨샵교육]C#, 윈폼, 네트워크, ado.net 실무프로젝트 과정
[씨샵학원/씨샵교육]C#, 윈폼, 네트워크, ado.net 실무프로젝트 과정
탑크리에듀(구로디지털단지역3번출구 2분거리)
 
[wpf학원,wpf교육]닷넷, c#기반 wpf 프로그래밍 인터페이스구현 재직자 향상과정
[wpf학원,wpf교육]닷넷, c#기반 wpf 프로그래밍 인터페이스구현 재직자 향상과정[wpf학원,wpf교육]닷넷, c#기반 wpf 프로그래밍 인터페이스구현 재직자 향상과정
[wpf학원,wpf교육]닷넷, c#기반 wpf 프로그래밍 인터페이스구현 재직자 향상과정
탑크리에듀(구로디지털단지역3번출구 2분거리)
 
[자마린교육/자마린실습]자바,스프링프레임워크(스프링부트) RESTful 웹서비스 구현 실습,자마린에서 스프링 웹서비스를 호출하고 응답 JS...
[자마린교육/자마린실습]자바,스프링프레임워크(스프링부트) RESTful 웹서비스 구현 실습,자마린에서 스프링 웹서비스를 호출하고 응답 JS...[자마린교육/자마린실습]자바,스프링프레임워크(스프링부트) RESTful 웹서비스 구현 실습,자마린에서 스프링 웹서비스를 호출하고 응답 JS...
[자마린교육/자마린실습]자바,스프링프레임워크(스프링부트) RESTful 웹서비스 구현 실습,자마린에서 스프링 웹서비스를 호출하고 응답 JS...
탑크리에듀(구로디지털단지역3번출구 2분거리)
 
[구로자마린학원/자마린강좌/자마린교육]3. xamarin.ios 3.3.5 추가적인 사항
[구로자마린학원/자마린강좌/자마린교육]3. xamarin.ios  3.3.5 추가적인 사항[구로자마린학원/자마린강좌/자마린교육]3. xamarin.ios  3.3.5 추가적인 사항
[구로자마린학원/자마린강좌/자마린교육]3. xamarin.ios 3.3.5 추가적인 사항
탑크리에듀(구로디지털단지역3번출구 2분거리)
 
3. xamarin.i os 3.3 xamarin.ios helloworld 자세히 살펴보기 3.4.4 view controllers an...
3. xamarin.i os 3.3 xamarin.ios helloworld 자세히 살펴보기 3.4.4 view controllers an...3. xamarin.i os 3.3 xamarin.ios helloworld 자세히 살펴보기 3.4.4 view controllers an...
3. xamarin.i os 3.3 xamarin.ios helloworld 자세히 살펴보기 3.4.4 view controllers an...
탑크리에듀(구로디지털단지역3번출구 2분거리)
 
5. 서브 쿼리(sub query) 5.1 서브 쿼리(sub query) 개요 5.2 단일행 서브쿼리(single row sub query)
5. 서브 쿼리(sub query) 5.1 서브 쿼리(sub query) 개요 5.2 단일행 서브쿼리(single row sub query)5. 서브 쿼리(sub query) 5.1 서브 쿼리(sub query) 개요 5.2 단일행 서브쿼리(single row sub query)
5. 서브 쿼리(sub query) 5.1 서브 쿼리(sub query) 개요 5.2 단일행 서브쿼리(single row sub query)
탑크리에듀(구로디지털단지역3번출구 2분거리)
 
3. xamarin.i os 3.1 xamarin.ios 설치, 개발환경 3.2 xamarin.ios helloworld(단일 뷰) 실습[...
3. xamarin.i os 3.1 xamarin.ios 설치, 개발환경 3.2 xamarin.ios helloworld(단일 뷰) 실습[...3. xamarin.i os 3.1 xamarin.ios 설치, 개발환경 3.2 xamarin.ios helloworld(단일 뷰) 실습[...
3. xamarin.i os 3.1 xamarin.ios 설치, 개발환경 3.2 xamarin.ios helloworld(단일 뷰) 실습[...
탑크리에듀(구로디지털단지역3번출구 2분거리)
 
자바, 웹 기초와 스프링 프레임워크 & 마이바티스 재직자 향상과정(자바학원/자바교육/자바기업출강]
자바, 웹 기초와 스프링 프레임워크 & 마이바티스 재직자 향상과정(자바학원/자바교육/자바기업출강]자바, 웹 기초와 스프링 프레임워크 & 마이바티스 재직자 향상과정(자바학원/자바교육/자바기업출강]
자바, 웹 기초와 스프링 프레임워크 & 마이바티스 재직자 향상과정(자바학원/자바교육/자바기업출강]
탑크리에듀(구로디지털단지역3번출구 2분거리)
 
3. xamarin.i os 3.1 xamarin.ios 설치, 개발환경 3.2 xamarin.ios helloworld_자마린학원_자마린...
3. xamarin.i os 3.1 xamarin.ios 설치, 개발환경 3.2 xamarin.ios helloworld_자마린학원_자마린...3. xamarin.i os 3.1 xamarin.ios 설치, 개발환경 3.2 xamarin.ios helloworld_자마린학원_자마린...
3. xamarin.i os 3.1 xamarin.ios 설치, 개발환경 3.2 xamarin.ios helloworld_자마린학원_자마린...
탑크리에듀(구로디지털단지역3번출구 2분거리)
 
3. 안드로이드 애플리케이션 구성요소 3.2인텐트 part01(안드로이드학원/안드로이드교육/안드로이드강좌/안드로이드기업출강]
3. 안드로이드 애플리케이션 구성요소 3.2인텐트 part01(안드로이드학원/안드로이드교육/안드로이드강좌/안드로이드기업출강]3. 안드로이드 애플리케이션 구성요소 3.2인텐트 part01(안드로이드학원/안드로이드교육/안드로이드강좌/안드로이드기업출강]
3. 안드로이드 애플리케이션 구성요소 3.2인텐트 part01(안드로이드학원/안드로이드교육/안드로이드강좌/안드로이드기업출강]
탑크리에듀(구로디지털단지역3번출구 2분거리)
 

Plus de 탑크리에듀(구로디지털단지역3번출구 2분거리) (20)

자마린.안드로이드 기본 내장레이아웃(Built-In List Item Layouts)
자마린.안드로이드 기본 내장레이아웃(Built-In List Item Layouts)자마린.안드로이드 기본 내장레이아웃(Built-In List Item Layouts)
자마린.안드로이드 기본 내장레이아웃(Built-In List Item Layouts)
 
(스프링프레임워크 강좌)스프링부트개요 및 HelloWorld 따라하기
(스프링프레임워크 강좌)스프링부트개요 및 HelloWorld 따라하기(스프링프레임워크 강좌)스프링부트개요 및 HelloWorld 따라하기
(스프링프레임워크 강좌)스프링부트개요 및 HelloWorld 따라하기
 
자마린 iOS 멀티화면 컨트롤러_네비게이션 컨트롤러, 루트 뷰 컨트롤러
자마린 iOS 멀티화면 컨트롤러_네비게이션 컨트롤러, 루트 뷰 컨트롤러자마린 iOS 멀티화면 컨트롤러_네비게이션 컨트롤러, 루트 뷰 컨트롤러
자마린 iOS 멀티화면 컨트롤러_네비게이션 컨트롤러, 루트 뷰 컨트롤러
 
[IT교육/IT학원]Develope를 위한 IT실무교육
[IT교육/IT학원]Develope를 위한 IT실무교육[IT교육/IT학원]Develope를 위한 IT실무교육
[IT교육/IT학원]Develope를 위한 IT실무교육
 
[아이오닉학원]아이오닉 하이브리드 앱 개발 과정(아이오닉2로 동적 모바일 앱 만들기)
[아이오닉학원]아이오닉 하이브리드 앱 개발 과정(아이오닉2로 동적 모바일 앱 만들기)[아이오닉학원]아이오닉 하이브리드 앱 개발 과정(아이오닉2로 동적 모바일 앱 만들기)
[아이오닉학원]아이오닉 하이브리드 앱 개발 과정(아이오닉2로 동적 모바일 앱 만들기)
 
[뷰제이에스학원]뷰제이에스(Vue.js) 프로그래밍 입문(프로그레시브 자바스크립트 프레임워크)
[뷰제이에스학원]뷰제이에스(Vue.js) 프로그래밍 입문(프로그레시브 자바스크립트 프레임워크)[뷰제이에스학원]뷰제이에스(Vue.js) 프로그래밍 입문(프로그레시브 자바스크립트 프레임워크)
[뷰제이에스학원]뷰제이에스(Vue.js) 프로그래밍 입문(프로그레시브 자바스크립트 프레임워크)
 
[씨샵학원/씨샵교육]C#, 윈폼, 네트워크, ado.net 실무프로젝트 과정
[씨샵학원/씨샵교육]C#, 윈폼, 네트워크, ado.net 실무프로젝트 과정[씨샵학원/씨샵교육]C#, 윈폼, 네트워크, ado.net 실무프로젝트 과정
[씨샵학원/씨샵교육]C#, 윈폼, 네트워크, ado.net 실무프로젝트 과정
 
[정보처리기사자격증학원]정보처리기사 취득 양성과정(국비무료 자격증과정)
[정보처리기사자격증학원]정보처리기사 취득 양성과정(국비무료 자격증과정)[정보처리기사자격증학원]정보처리기사 취득 양성과정(국비무료 자격증과정)
[정보처리기사자격증학원]정보처리기사 취득 양성과정(국비무료 자격증과정)
 
[wpf학원,wpf교육]닷넷, c#기반 wpf 프로그래밍 인터페이스구현 재직자 향상과정
[wpf학원,wpf교육]닷넷, c#기반 wpf 프로그래밍 인터페이스구현 재직자 향상과정[wpf학원,wpf교육]닷넷, c#기반 wpf 프로그래밍 인터페이스구현 재직자 향상과정
[wpf학원,wpf교육]닷넷, c#기반 wpf 프로그래밍 인터페이스구현 재직자 향상과정
 
(WPF교육)ListBox와 Linq 쿼리를 이용한 간단한 데이터바인딩, 새창 띄우기, 이벤트 및 델리게이트를 통한 메인윈도우의 ListB...
(WPF교육)ListBox와 Linq 쿼리를 이용한 간단한 데이터바인딩, 새창 띄우기, 이벤트 및 델리게이트를 통한 메인윈도우의 ListB...(WPF교육)ListBox와 Linq 쿼리를 이용한 간단한 데이터바인딩, 새창 띄우기, 이벤트 및 델리게이트를 통한 메인윈도우의 ListB...
(WPF교육)ListBox와 Linq 쿼리를 이용한 간단한 데이터바인딩, 새창 띄우기, 이벤트 및 델리게이트를 통한 메인윈도우의 ListB...
 
[자마린교육/자마린실습]자바,스프링프레임워크(스프링부트) RESTful 웹서비스 구현 실습,자마린에서 스프링 웹서비스를 호출하고 응답 JS...
[자마린교육/자마린실습]자바,스프링프레임워크(스프링부트) RESTful 웹서비스 구현 실습,자마린에서 스프링 웹서비스를 호출하고 응답 JS...[자마린교육/자마린실습]자바,스프링프레임워크(스프링부트) RESTful 웹서비스 구현 실습,자마린에서 스프링 웹서비스를 호출하고 응답 JS...
[자마린교육/자마린실습]자바,스프링프레임워크(스프링부트) RESTful 웹서비스 구현 실습,자마린에서 스프링 웹서비스를 호출하고 응답 JS...
 
[구로자마린학원/자마린강좌/자마린교육]3. xamarin.ios 3.3.5 추가적인 사항
[구로자마린학원/자마린강좌/자마린교육]3. xamarin.ios  3.3.5 추가적인 사항[구로자마린학원/자마린강좌/자마린교육]3. xamarin.ios  3.3.5 추가적인 사항
[구로자마린학원/자마린강좌/자마린교육]3. xamarin.ios 3.3.5 추가적인 사항
 
3. xamarin.i os 3.3 xamarin.ios helloworld 자세히 살펴보기 3.4.4 view controllers an...
3. xamarin.i os 3.3 xamarin.ios helloworld 자세히 살펴보기 3.4.4 view controllers an...3. xamarin.i os 3.3 xamarin.ios helloworld 자세히 살펴보기 3.4.4 view controllers an...
3. xamarin.i os 3.3 xamarin.ios helloworld 자세히 살펴보기 3.4.4 view controllers an...
 
5. 서브 쿼리(sub query) 5.1 서브 쿼리(sub query) 개요 5.2 단일행 서브쿼리(single row sub query)
5. 서브 쿼리(sub query) 5.1 서브 쿼리(sub query) 개요 5.2 단일행 서브쿼리(single row sub query)5. 서브 쿼리(sub query) 5.1 서브 쿼리(sub query) 개요 5.2 단일행 서브쿼리(single row sub query)
5. 서브 쿼리(sub query) 5.1 서브 쿼리(sub query) 개요 5.2 단일행 서브쿼리(single row sub query)
 
3. xamarin.i os 3.1 xamarin.ios 설치, 개발환경 3.2 xamarin.ios helloworld(단일 뷰) 실습[...
3. xamarin.i os 3.1 xamarin.ios 설치, 개발환경 3.2 xamarin.ios helloworld(단일 뷰) 실습[...3. xamarin.i os 3.1 xamarin.ios 설치, 개발환경 3.2 xamarin.ios helloworld(단일 뷰) 실습[...
3. xamarin.i os 3.1 xamarin.ios 설치, 개발환경 3.2 xamarin.ios helloworld(단일 뷰) 실습[...
 
(닷넷,자마린,아이폰실습)Xamarin.iOS HelloWorld 실습_멀티화면,화면전환_Xamarin교육/Xamarin강좌
(닷넷,자마린,아이폰실습)Xamarin.iOS HelloWorld 실습_멀티화면,화면전환_Xamarin교육/Xamarin강좌(닷넷,자마린,아이폰실습)Xamarin.iOS HelloWorld 실습_멀티화면,화면전환_Xamarin교육/Xamarin강좌
(닷넷,자마린,아이폰실습)Xamarin.iOS HelloWorld 실습_멀티화면,화면전환_Xamarin교육/Xamarin강좌
 
C#기초에서 윈도우, 스마트폰 앱개발 과정(c#.net, ado.net, win form, wpf, 자마린)_자마린학원_씨샵교육_WPF학원...
C#기초에서 윈도우, 스마트폰 앱개발 과정(c#.net, ado.net, win form, wpf, 자마린)_자마린학원_씨샵교육_WPF학원...C#기초에서 윈도우, 스마트폰 앱개발 과정(c#.net, ado.net, win form, wpf, 자마린)_자마린학원_씨샵교육_WPF학원...
C#기초에서 윈도우, 스마트폰 앱개발 과정(c#.net, ado.net, win form, wpf, 자마린)_자마린학원_씨샵교육_WPF학원...
 
자바, 웹 기초와 스프링 프레임워크 & 마이바티스 재직자 향상과정(자바학원/자바교육/자바기업출강]
자바, 웹 기초와 스프링 프레임워크 & 마이바티스 재직자 향상과정(자바학원/자바교육/자바기업출강]자바, 웹 기초와 스프링 프레임워크 & 마이바티스 재직자 향상과정(자바학원/자바교육/자바기업출강]
자바, 웹 기초와 스프링 프레임워크 & 마이바티스 재직자 향상과정(자바학원/자바교육/자바기업출강]
 
3. xamarin.i os 3.1 xamarin.ios 설치, 개발환경 3.2 xamarin.ios helloworld_자마린학원_자마린...
3. xamarin.i os 3.1 xamarin.ios 설치, 개발환경 3.2 xamarin.ios helloworld_자마린학원_자마린...3. xamarin.i os 3.1 xamarin.ios 설치, 개발환경 3.2 xamarin.ios helloworld_자마린학원_자마린...
3. xamarin.i os 3.1 xamarin.ios 설치, 개발환경 3.2 xamarin.ios helloworld_자마린학원_자마린...
 
3. 안드로이드 애플리케이션 구성요소 3.2인텐트 part01(안드로이드학원/안드로이드교육/안드로이드강좌/안드로이드기업출강]
3. 안드로이드 애플리케이션 구성요소 3.2인텐트 part01(안드로이드학원/안드로이드교육/안드로이드강좌/안드로이드기업출강]3. 안드로이드 애플리케이션 구성요소 3.2인텐트 part01(안드로이드학원/안드로이드교육/안드로이드강좌/안드로이드기업출강]
3. 안드로이드 애플리케이션 구성요소 3.2인텐트 part01(안드로이드학원/안드로이드교육/안드로이드강좌/안드로이드기업출강]
 

Dernier

Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Dernier (20)

Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 

9.Spring DI_4

  • 2. Spring Framework_Spring Ioc & DI Spring IoC & DI 5. Spring DI 10) 스프링에서 XML 설정 파일의 분리 XML 설정파일을 여러 개로 분리할 수 있으며 이 경우 ref bean 태그를 사용하여 자바 빈을 로딩하면된다. ApplicationContext를 생성할 때 여러 XML 파일명을 문자열 배열로 넣어주면 된다. package ojc.spring.twoxml; public interface Dog { public void jitda(); } [Dog.java]
  • 3. Spring Framework_Spring Ioc & DI package ojc.spring.twoxml; import org.springframework.stereotype.Component; public class Pudle implements Dog { public void jitda() { System.out.println("푸들푸들~"); } } [Pudle.java] package ojc.spring.twoxml; import org.springframework.stereotype.Component; public class Jindo implements Dog{ public void jitda() { System.out.println("진도진도~"); } } [Jindo.java]
  • 4. Spring Framework_Spring Ioc & DI package ojc.spring.twoxml; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; public class DogManager { private Pudle pudle; private Jindo jindo; public void setPudle(Pudle pudle) { this.pudle = pudle; } public void setJindo(Jindo jindo) { this.jindo = jindo; } public void walwal() { this.jindo.jitda(); this.pudle.jitda(); } } [DogManager.java]
  • 5. Spring Framework_Spring Ioc & DI package ojc.spring.twoxml; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class DogApp { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"applicationContext.xml", "dog.xml"}); DogManager dManager = (DogManager) context.getBean("dogManager"); dManager.walwal(); } } [DogApp.java]
  • 6. Spring Framework_Spring Ioc & DI <?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-4.2.xsd"> <bean id="dogManager" class="ojc.spring.twoxml.DogManager"> <property name="pudle"> <ref bean="pudle"></ref> </property> <propertyname="jindo"> <ref bean="jindo"></ref> </property> </bean> </beans> [src/main/resources/applicationContext.xml]
  • 7. Spring Framework_Spring Ioc & DI <?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-4.2.xsd"> <bean id="pudle" class="ojc.spring.twoxml.Pudle"/> <bean id="jindo" class="ojc.spring.twoxml.Jindo"/> </beans> [src/main/resources/dog.xml] 진도진도~ 푸들푸들~ [결과]
  • 8. Spring Framework_Spring Ioc & DI 11) ApplicationContext의 분리(부모, 자식) 한 컨텍스는 다른 컨텍스트의 부모가 될 수 있다. 자식 컨텍스에 있는 빈이 부모 컨텍스트에 있는 빈 참조 가능한 데 스프링은 ApplicationContext 중첩 기능을 제공함으로서 설정을 여러 파일로 나눌 수 있게 해준다. 자식 컨텍스트에서 부모컨텍스트의 빈을 참조하는 방식은 동일하다. 단, 이름이 같은 것이 있다면 ref 태그에서 parent 속성을 사용하면 된다. <?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-4.2.xsd"> <bean id="parent1" class="java.lang.String"> <constructor-arg> <value>parent bean 1</value> </constructor-arg> </bean> <bean id="parent2" class="java.lang.String"> <constructor-arg> <value>parent bean 2</value> </constructor-arg> </bean> </beans> [parent.java]
  • 9. Spring Framework_Spring Ioc & DI <?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-4.2.xsd"> <bean id="target1" class="onj.context.overlap.Onj"> <property name="val1"> <ref bean="parent1"/> </property> </bean> <bean id="target2" class="onj.context.overlap.Onj"> <property name="val2"> <ref parent="parent2"/> <!–부모context에서 parent2라는 id,name을 검색 </property> </bean> <bean id="parent2" class="java.lang.String"> <constructor-arg> <value>child bean 2</value> </constructor-arg> </bean> </beans> [child.xml]
  • 10. Spring Framework_Spring Ioc & DI package onj.context.overlap; public class Onj { private String val1; private String val2; public String getVal1() { return val1; } public void setVal1(String val1) { this.val1 = val1; } public String getVal2() { return val2; } public void setVal2(String val2) { this.val2 = val2; } } [Onj.java]
  • 11. Spring Framework_Spring Ioc & DI package onj.context.overlap; import org.springframework.context.support.GenericXmlApplicationContext; public class ContextOverlapExam { public static void main(String[] args) { GenericXmlApplicationContext parent= new GenericXmlApplicationContext(); parent.load("classpath:parent.xml"); parent.refresh(); GenericXmlApplicationContext child = new GenericXmlApplicationContext(); child.load("classpath:child.xml"); child.setParent(parent); child.refresh(); Onj target1 = (Onj) child.getBean("target1"); Onj target2 = (Onj) child.getBean("target2"); String target3 = (String) child.getBean("parent2"); System.out.println(target1.getVal1()); System.out.println(target2.getVal2()); System.out.println(target3); } } [ContextOverlapExam.java]
  • 12. Spring Framework_Spring Ioc & DI 12) 컬렉션 주입, XML 방식 빈에서 개별 빈이나 값이 아닌 객체의 컬렉션에 접근해야 되는 경우가있는데 <list>, <map>, <set>, <prop>를 사용한다. 자바에서 Properties 클래스는property 값으로 String을 지원하므로 String만 넘길 수 있다. <?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-4.2.xsd"> <bean id="onj" name="onjName" class="onj.injection.collection.Onj"/> <bean id="sample" class="onj.injection.collection.CollectionExam"> <property name="map"> <map> <entry key="someValue"> <value>hello map...</value> </entry> <entry key="someBean"> <ref bean="onj"/> </entry> </map> [app-context5.xml]
  • 13. Spring Framework_Spring Ioc & DI </property> <property name="set"> <set> <value>hello list...</value> <ref bean="onj"/> </set> </property> <property name="props"> <props> <prop key="firstName">Jong Cheol</prop> <prop key="lastName">Lee</prop> </props> </property> </bean> </beans> [app-context5.xml]
  • 14. Spring Framework_Spring Ioc & DI public void display() { for(Map.Entry<String, Object> entry:map.entrySet()) { System.out.println("Key: " + entry.getKey() + "-" + entry.getValue()); } for(Map.Entry<Object, Object> entry : props.entrySet()) { System.out.println("key : " + entry.getKey() + "-" + entry.getValue() ); } for(Object obj : set) { System.out.println("value : " + obj); } } public static void main(String[] args) { GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); ctx.load("classpath:app-context5.xml"); ctx.refresh(); CollectionExam col = (CollectionExam)ctx.getBean("sample“) col.display(); } [CollectionExam.java]
  • 15. Spring Framework_Spring Ioc & DI 12) 컬렉션 주입, 어노테이션 방식 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd"> <context:annotation-config/> <context:component-scan base-package="onj.collection.annotation" /> <bean id="onj" name="onjName" class="onj.collection.annotation.Onj"/> <util:map id="map" map-class="java.util.HashMap"> <entry key="someValue"> <value>hello... map</value> </entry> [app-context6.xml]
  • 16. Spring Framework_Spring Ioc & DI <entry key="someBean"> <ref ben="onj"/> </entry> </util:map> <util:properties id="props"> <prop key="firstName">Jong Cheol</prop> <prop key="lastName">Lee</prop> </util:properties> <util:set id="set"> <value>hello.... set</value> <ref bean="onj"/> </util:set> </beans> [app-context6.xml]
  • 17. Spring Framework_Spring Ioc & DI package onj.collection.annotation; import org.springframework.stereotype.Service; @Service("onj") public class Onj { public String toString() { return "my name is OnJ"; } } [Onj.java]
  • 18. Spring Framework_Spring Ioc & DI … … @Service("sample") public class CollectionAnnotationExam { @Resource(name="map") private Map<String, Object> map ; @Resource(name="props") private Properties props; @Resource(name="set") private Set<Object> set; … … … [CollectionAnnotationExam.java]