Ray's playground

 

Springing into action(Chapter 1 of Spring In Action)

HelloApp
 1 package com.springinaction.chapter1.hello;
 2 
 3 import org.springframework.beans.factory.BeanFactory;
 4 import org.springframework.beans.factory.xml.XmlBeanFactory;
 5 import org.springframework.core.io.FileSystemResource;
 6 
 7 
 8 public class HelloApp {
 9     public static void main(String[] args) throws Exception
10     {
11         BeanFactory factory = new XmlBeanFactory(new FileSystemResource("resources\\hello.xml"));
12         
13         GreetingService greetingService = (GreetingService)factory.getBean("greetingService");
14         greetingService.SayHello();
15     }
16 }

 

hello.xml
 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-2.5.xsd">
 6 <bean id="greetingService"
 7 class="com.springinaction.chapter1.hello.GreetingServiceImpl">
 8 <property name="greeting" value="Buenos Dias!" />
 9 </bean>
10 </beans>

 

 

GreetingServiceImpl
 1 package com.springinaction.chapter1.hello;
 2 
 3 public class GreetingServiceImpl implements GreetingService {
 4     private String greeting;
 5         
 6     public String getGreeting() {
 7         return greeting;
 8     }
 9 
10     public void setGreeting(String greeting) {
11         this.greeting = greeting;
12     }
13 
14     public GreetingServiceImpl(){}
15     
16     public GreetingServiceImpl(String greeting)
17     {
18         this.greeting = greeting;
19     }
20     
21     @Override
22     public void SayHello() {
23         // TODO Auto-generated method stub
24         System.out.println("hello " + greeting);
25     }
26 
27 }

 

 

1 package com.springinaction.chapter1.hello;
2 
3 public interface GreetingService {
4     void SayHello();
5 }

 

 

posted on 2010-06-19 23:27  Ray Z  阅读(227)  评论(0编辑  收藏  举报

导航