새로운 Project를 실행시킨다.

Spring lib를 Build Path에 추가한다.

----------------------------------------------
 1. Service를 할 Class를 만든다.
HelloSpring3.java

public class HelloSpring3{
    public void sayHello(){
        System.out.println("Hi Spring!!");
    }
}

2. Spring 설정파일을 만든다.
Spring-Hello.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" 

xmlns:aop="http://www.springframework.org/schema/aop"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">


<bean id="HelloSpringBean" class="HelloSpring"/>

</beans> 

: Spring의 특징은 실행되는 시점에 설정대로 동작을 한다는 뜻인데
XML에서 설정한 Bean ID 인 HelloSpringBean이라는 것을 호출하면 HelloSpring 이라는 Class가 응답을 한다는 뜻이다.
 *** 해당 XML 파일은 소스폴더에 있어야 한다.
 
3. 실행하기
 Hello.java
public class Hello{
    public static void main(String[] args){
        XmlBeanFactory beanFactory
      = new XmlBeanFactory(new ClassPathResource("Spring-Hello.xml"));
    HelloSpring myBean        
      = (HelloSpring)beanFactory.getBean("HelloSpringBean");

    myBean.sayHello();

    }
}

XML에서 Bean을 가져올 것이므로 XmlBeanFactory를 사용한다.
해당 XML은 Source 폴더 즉. Classpath에 있으므로 ClassPathResource를 사용한다.
=>ClassPath에 있는 Xml파일을 읽어서 Bean으로 사용한다.

BeanFactory에서 Id를 읽어 Class를 생성한다.
생성한 Class의 method를 실행한다. 
728x90
BLOG main image
"그게 뭐 어쨌다는 거냐?" 늘 누가 나에게 나에대한 말을할 때면 이말을 기억해라. by nobang

카테고리

nobang이야기 (1933)
Life With Gopro (7)
Life With Mini (79)
Diary (971)
너 그거 아니(do you know) (162)
난 그래 (159)
Study (290)
속지말자 (10)
Project (34)
Poem (15)
Song (0)
Photo (113)
낙서장 (45)
일정 (0)
C.A.P.i (2)
PodCast (0)
nobang (27)
고한친구들 (4)
recieve (0)
History (0)
android_app (2)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

Total :
Today : Yesterday :