Skip to content

Commit 389d2fc

Browse files
committed
genericXmlApplicationContext
1 parent 52fd582 commit 389d2fc

File tree

86 files changed

+225
-1775
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+225
-1775
lines changed

VOL1/ch07_2/.idea/jpa-buddy.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VOL1/ch07_2/.idea/misc.xml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VOL2/ch01/.idea/ch01.iml

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VOL2/ch01/.idea/jpa-buddy.xml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VOL2/ch01/.idea/libraries/Java_EE_6_Java_EE_6.xml

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VOL2/ch01/.idea/libraries/libs_3.xml

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VOL2/ch01/.idea/uiDesigner.xml

+124
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VOL2/ch01/lib/javax.annotation.jar

7.53 KB
Binary file not shown.

VOL2/ch01/lib/javax.ejb.jar

46.5 KB
Binary file not shown.

VOL2/ch01/lib/javax.jms.jar

25.3 KB
Binary file not shown.

VOL2/ch01/lib/javax.persistence.jar

127 KB
Binary file not shown.

VOL2/ch01/lib/javax.resource.jar

43.5 KB
Binary file not shown.

VOL2/ch01/lib/javax.servlet.jar

68.3 KB
Binary file not shown.

VOL2/ch01/lib/javax.servlet.jsp.jar

77 KB
Binary file not shown.
27.5 KB
Binary file not shown.

VOL2/ch01/lib/javax.transaction.jar

9.49 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://www.springframework.org/schema/beans
5+
http://www.springframework.org/schema/beans/spring-beans.xsd">
6+
7+
<bean id ="hello" class="springbook.learningtest.spring.ioc.Hello">
8+
<property name="name" value="Spring"/>
9+
<property name="printer" ref="printer"/>
10+
11+
</bean>
12+
<bean id="printer" class="springbook.learningtest.spring.ioc.StringPrinter"/>
13+
14+
</beans>

VOL2/ch01/src/springbook/learningtest/spring/ConsolePrinter.java VOL2/ch01/src/springbook/learningtest/spring/ioc/ConsolePrinter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package springbook.learningtest.spring;
1+
package springbook.learningtest.spring.ioc;
22

33
public class ConsolePrinter implements Printer{
44
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://www.springframework.org/schema/beans
5+
http://www.springframework.org/schema/beans/spring-beans.xsd">
6+
7+
<bean id ="hello" class="springbook.learningtest.spring.ioc.Hello">
8+
<property name="name" value="Spring"/>
9+
<property name="printer" ref="printer"/>
10+
11+
</bean>
12+
<bean id="printer" class="springbook.learningtest.spring.ioc.StringPrinter"/>
13+
14+
</beans>

VOL2/ch01/src/springbook/learningtest/spring/Hello.java VOL2/ch01/src/springbook/learningtest/spring/ioc/Hello.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package springbook.learningtest.spring;
1+
package springbook.learningtest.spring.ioc;
22

33

44
public class Hello {

VOL2/ch01/src/springbook/learningtest/HelloBeanTest.java VOL2/ch01/src/springbook/learningtest/spring/ioc/HelloBeanTest.java

+27-6
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
package springbook.learningtest;
1+
package springbook.learningtest.spring.ioc;
22

3-
import org.junit.Assert;
43
import org.junit.Test;
54
import org.springframework.beans.factory.config.BeanDefinition;
6-
import org.springframework.beans.factory.config.RuntimeBeanNameReference;
75
import org.springframework.beans.factory.config.RuntimeBeanReference;
86
import org.springframework.beans.factory.support.RootBeanDefinition;
7+
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
8+
import org.springframework.context.support.GenericApplicationContext;
9+
import org.springframework.context.support.GenericXmlApplicationContext;
910
import org.springframework.context.support.StaticApplicationContext;
10-
import springbook.learningtest.spring.Hello;
11-
import springbook.learningtest.spring.StringPrinter;
1211

1312
import static org.hamcrest.CoreMatchers.*;
1413
import static org.junit.Assert.assertThat;
1514

1615
public class HelloBeanTest {
1716

1817
@Test
19-
public void staticApplicationContext() {
18+
public void registerBean() {
2019
StaticApplicationContext ac = new StaticApplicationContext(); //IoC 컨테이너 생성. 생성과 동시에 컨테이너로 동작
2120
ac.registerSingleton("hello1", Hello.class); //Hello 클래스를 hello이라는 이름의 싱글톤 빈으로 컨테이너에 등록
2221
//registerSingleton : 디폴트 메타정보를 사용해서 싱글톤 빈을 등록한다.
@@ -53,6 +52,28 @@ public void registerBeanWithDependency(){
5352
assertThat(ac.getBean("printer").toString(), is("Hello Spring"));
5453
}
5554

55+
@Test
56+
public void genericApplicationContext(){
57+
GenericApplicationContext ac = new GenericApplicationContext();
58+
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ac);
59+
reader.loadBeanDefinitions("/springbook/learningtest/spring/ioc/GenericApplicationContext.xml");
60+
ac.refresh(); //모든 메타정보가 등록되었으니 애플리케이션 컨테이너를 초기화하라는 명령이다
61+
62+
Hello hello = ac.getBean("hello", Hello.class);
63+
hello.print();
64+
65+
assertThat(ac.getBean("printer").toString(), is("Hello Spring"));
66+
}
67+
@Test
68+
public void genericXmlApplicationContext(){
69+
GenericXmlApplicationContext ac = new GenericXmlApplicationContext("/springbook/learningtest/spring/ioc/GenericApplicationContext.xml");
70+
71+
Hello hello = ac.getBean("hello", Hello.class);
72+
hello.print();
73+
74+
assertThat(ac.getBean("printer").toString(), is("Hello Spring"));
75+
}
76+
5677

5778
}
5879

VOL2/ch01/src/springbook/learningtest/spring/Printer.java VOL2/ch01/src/springbook/learningtest/spring/ioc/Printer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package springbook.learningtest.spring;
1+
package springbook.learningtest.spring.ioc;
22

33
public interface Printer {
44
void print(String sayHello);

VOL2/ch01/src/springbook/learningtest/spring/StringPrinter.java VOL2/ch01/src/springbook/learningtest/spring/ioc/StringPrinter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package springbook.learningtest.spring;
1+
package springbook.learningtest.spring.ioc;
22

33

44
public class StringPrinter implements Printer {

VOL2/ch01/src/springbook/user/AbstractUpdatableSqlRegistryTest.java

-63
This file was deleted.

VOL2/ch01/src/springbook/user/ConcurrentHashMapSqlRegistryTest.java

-14
This file was deleted.

0 commit comments

Comments
 (0)