티스토리 뷰

HelloWorldService
package egovframework.guide.helloworld;

public interface HelloWorldService {
 public String sayHello();
}


HelloWorldServiceImpl
package egovframework.guide.helloworld;

public class HelloWorldServiceImpl implements HelloWorldService{

 private String name;
   
 public void setName(String name) {
  this.name = name;
 }

 public String sayHello() {
  return "Hello " + name + "!!!" ;
 }
}


common-servlet.xml :  helloworld를 name 속성으로 서비스 구현클래스를 정의하고 있으며 해당 서비스의 name 속성을 “egov framework”로 선언하였다.
<?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"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> 
 <context:annotation-config/>
 
 <bean name="helloworld" class="egovframework.guide.helloworld.HelloWorldServiceImpl">
  <property name="name">
   <value>egov framework</value>
  </property>
 </bean>
 
</beans>



HelloWorld 서비스를 실행하기 위한 클라이언트 클래스

package egovframework.guide.helloworld;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class HelloWorldClient {
 
 private static Log logger = LogFactory.getLog(HelloWorldClient.class);

 /**
  * @param args
  */
 public static void main(String[] args) {
  String configLocation = "context-helloworld.xml"; 
  ApplicationContext context = new ClassPathXmlApplicationContext(configLocation);
  HelloWorldService helloworld = (HelloWorldSer-vice)context.getBean("helloworld");
 
  logger.debug(helloworld.sayHello());
 }





공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/09   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함
반응형