<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 32,comments - 8,trackbacks - 0

    Oops! Spring Framework Quick Start!


    eclipse europa + tomcat 5.5+spring 2.06+lomboz S3.3RC1


    Purpose:

    完成這個項目,能夠對spring框架有個整體認識,包括IoC之類的。

    Prerequisite:

    eclipse-java-europa-win32.zip

    apache-tomcat-5.5.23.exe

    tomcatPluginV31.zip

    spring-framework-2.0.6-with-dependencies.zip

    org.objectweb.lomboz-and-prereqs-S-3.3RC1-200708181505.zip


    Reference:

    http://www.tkk7.com/pixysoft/archive/2007/08/29/141048.html 



    Chapter 01
     

    新建一個Java Project,項目名為OopsSpringFramework

     

     

     

    選擇project – properties – Libraries添加以下類庫。所有類庫可以在spring-framework-2.0.6.zip里面找到,包括dist目錄和lib目錄里面。

     

     

     

    src目錄下面添加以下文件:



    beanRefDataAccess.xml

    <?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="helloWorldDAO1" class="HelloWorld1" />
        
    <bean id="helloWorldDAO2" class="HelloWorld2" />
    </beans>


    beanRefFactory.xml

    <?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="beanFactory"
            class
    ="org.springframework.context.support.ClassPathXmlApplicationContext">
            
    <constructor-arg>
                
    <list>
                    
    <value>beanRefDataAccess.xml</value>
                    
    <value>beanRefService.xml</value>
                    
    <value>beanRefMVC.xml</value>
                
    </list>
            
    </constructor-arg>
        
    </bean>
    </beans>


    beanRefMVC.xml

    <?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="helloWorldMVC1" class="HelloWorld1" />
        
    <bean id="helloWorldMVC2" class="HelloWorld2" />
    </beans>

    beanRefService.xml

    <?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="helloWorld1" class="HelloWorld1" />
        
    <bean id="helloWorld2" class="HelloWorld2" />
        
    <bean id="springDemoConstructor" class="SpringDemoConstructor">
            
    <constructor-arg>
                
    <value>Spring IDE Constructor</value>
            
    </constructor-arg>
            
    <property name="helloWorld">
                
    <ref bean="helloWorld1"></ref>
            
    </property>
        
    </bean>
        
    <bean id="springDemoSetter" class="SpringDemoSetter">
            
    <property name="hello" value="Spring IDE Setter" />
            
    <property name="helloWorld">
                
    <ref bean="helloWorld2"></ref>
            
    </property>
        
    </bean>
    </beans>


    HelloWorld1.java

    public class HelloWorld1 implements IHelloWorld
    {
        
    public HelloWorld1()
        {
            
    super();
        }

        
    public String sayHelloWorld()
        {
            
    return "Hello World HelloWorld1";
        }
    }

    HelloWorld2.java

    public class HelloWorld2 implements IHelloWorld
    {
        
    public HelloWorld2()
        {
            
    super();
        }

        
    public String sayHelloWorld()
        {
            
    return "Hello World HelloWorld2";
        }
    }

    IHelloWorld.java

     

    public interface IHelloWorld
    {
        String sayHelloWorld();
    }


    ISpringDemo.java

    public interface ISpringDemo
    {
        IHelloWorld getHelloWorld();

        String getHello();
    }


    ServiceFactory.java

    import org.springframework.beans.factory.BeanFactory;
    import org.springframework.beans.factory.access.BeanFactoryLocator;
    import org.springframework.beans.factory.access.BeanFactoryReference;
    import org.springframework.beans.factory.access.SingletonBeanFactoryLocator;

    public final class ServiceFactory
    {
        
    private static BeanFactoryLocator bfLocator = null;
        
    private static BeanFactoryReference bfReference = null;
        
    private static BeanFactory factory = null;
        
    static
        {
            bfLocator 
    = SingletonBeanFactoryLocator.getInstance();
            bfReference 
    = bfLocator.useBeanFactory("beanFactory");
            factory 
    = bfReference.getFactory();
        }

        
    private ServiceFactory()
        {
            
    super();
        }

        
    public static Object getBeanByName(final String beanName)
        {
            
    return factory.getBean(beanName);
        }
    }

    SpringDemoConstructor.java

    public class SpringDemoConstructor implements ISpringDemo
    {
        
    private String hello;
        
    private IHelloWorld helloWorld;

        
    public SpringDemoConstructor(String hello)
        {
            
    this.hello = hello;
        }

        
    public String getHello()
        {
            
    return hello;
        }

        
    public IHelloWorld getHelloWorld()
        {
            
    return helloWorld;
        }

        
    public void setHelloWorld(IHelloWorld helloWorld)
        {
            
    this.helloWorld = helloWorld;
        }
    }

    SpringDemoSetter.java

    public class SpringDemoSetter implements ISpringDemo
    {
        
    private String hello;
        
    private IHelloWorld helloWorld;

        
    public String getHello()
        {
            
    return hello;
        }

        
    public void setHello(String hello)
        {
            
    this.hello = hello;
        }

        
    public IHelloWorld getHelloWorld()
        {
            
    return helloWorld;
        }

        
    public void setHelloWorld(IHelloWorld helloWorld)
        {
            
    this.helloWorld = helloWorld;
        }
    }


    SpringIDETest.java

    import junit.framework.TestCase;

    public class SpringIDETest extends TestCase
    {
        
    private IHelloWorld helloWorld = null;
        
    private ISpringDemo springDemo = null;
        
    private final static String hello1 = "Hello World HelloWorld1";
        
    private final static String hello2 = "Hello World HelloWorld2";
        
    private final static String helloset = "Spring IDE Setter";
        
    private final static String hellocon = "Spring IDE Constructor";

        
    public void testSpringBeans()
        {
            helloWorld 
    = (IHelloWorld) ServiceFactory.getBeanByName("helloWorld1");
            assertEquals(hello1, helloWorld.sayHelloWorld());
            helloWorld 
    = (IHelloWorld) ServiceFactory.getBeanByName("helloWorld2");
            assertEquals(hello2, helloWorld.sayHelloWorld());
        }

        
    public void testIoCConstructor()
        {
            
    // Constructor
            springDemo = (ISpringDemo) ServiceFactory
                    .getBeanByName(
    "springDemoConstructor");
            assertEquals(hellocon, springDemo.getHello());
            assertEquals(hello1, springDemo.getHelloWorld().sayHelloWorld());
        }

        
    public void testIoCSetter()
        {
            
    // Setter
            springDemo = (ISpringDemo) ServiceFactory
                    .getBeanByName(
    "springDemoSetter");
            assertEquals(helloset, springDemo.getHello());
            assertEquals(hello2, springDemo.getHelloWorld().sayHelloWorld());
        }
    }




    鼠標右點擊OopsSpringFramework,選擇 Add Spring Project Nature


     

    打開Spring Explorer窗口

     

     

     



    SpringExplorer里面右選擇項目,properties.



    選擇
    Beans Support,Add xml



     

    之后得到以下內容


     

    選擇Config SetsNew,輸入以下內容

     

    之后Spring-Explorer出現以下內容



    右鍵點擊項目,選擇Run as.. JUnit …

     


    完成!


    posted on 2007-08-30 10:11 張辰 閱讀(891) 評論(0)  編輯  收藏 所屬分類: Dr. Oops
    主站蜘蛛池模板: 国产亚洲高清在线精品不卡| 国产h视频在线观看免费| 色婷婷六月亚洲综合香蕉| 亚洲色图在线播放| 亚洲自偷自偷偷色无码中文| 热久久精品免费视频| 国产免费的野战视频| 香蕉成人免费看片视频app下载| 亚洲一区免费视频| a在线观看免费视频| 水蜜桃视频在线观看免费| 亚洲精华国产精华精华液| 久久综合日韩亚洲精品色| 亚洲美女在线国产| 可以免费观看一级毛片黄a | 久久99久久成人免费播放| 亚洲aⅴ天堂av天堂无码麻豆| 亚洲AV蜜桃永久无码精品| 久久不见久久见中文字幕免费| 亚洲欧美国产国产综合一区| 亚洲黄色免费网站| 久久久久久a亚洲欧洲AV| 狠狠色婷婷狠狠狠亚洲综合| 免费在线观看日韩| 免费国内精品久久久久影院| 日韩高清免费在线观看| 午夜免费福利在线观看| 全免费a级毛片免费看不卡| 青青草a免费线观a| 女人18一级毛片免费观看| 毛片a级三毛片免费播放| 成年女人男人免费视频播放| 91在线视频免费看| 最近中文字幕mv免费高清电影| 99视频免费在线观看| 中文字幕视频在线免费观看| 国产免费一区二区视频| 日韩免费在线视频| 久久精品免费一区二区| 亚洲免费观看网站| 毛片免费视频在线观看|