'스프링'에 해당되는 글 1건

  1. 2008.10.21 Spring Practice
인터페이스를 작성
1
2
3
4
5
6
7
8
9
10
/**
 * 인터페이스
 */
package com.matthias.spring.chap01.hello;

public interface GreetingService {
	
	public void sayGreeting();

}

인사말을 출력하는 클래스
/**
 * 인터페이스를 구현하는 클래스
 */
package com.matthias.spring.chap01.hello;

public class GreetingServiceImpl implements GreetingService {
	
	private String greeting;

	public GreetingServiceImpl() {
	}
	
	public GreetingServiceImpl(String _greeting) {
		this.greeting = _greeting;
	}
	
	public void sayGreeting() {
		System.out.println(greeting);
	}
	
	public void setGreeting(String greeting) {
		this.greeting = greeting;
	}
}

스프링으로 HelloWorld 설정
1
2
3
4
5
6
7
8
9
10
11
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
	<bean id="greetingService" class="com.matthias.spring.chap01.hello.GreetingServiceImpl">
		<property name="greeting">
			<value>Buenos Dias!</value>
		</property>
	</bean>
</beans>

HelloWorld 메인 클래스
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package com.matthias.spring.chap01.hello;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;

public class HelloWorld {
	
	public static void main(String args[]) {
		BeanFactory factory =
			new XmlBeanFactory(new FileSystemResource("HelloWorld.xml"));
		GreetingService greetingService =
			(GreetingService) factory.getBean("greetingService");
		
		greetingService.sayGreeting();
	}
}
저작자 표시
신고
크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by 영겁회귀

티스토리 툴바