随笔 - 303  文章 - 883  trackbacks - 0
<2007年9月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

欢迎光临! 
闲聊 QQ:1074961813

随笔分类(357)

我管理的群

公共blog

  • n维空间
  • Email : java3d@126.com 群 : 12999758

参与管理的论坛

好友的blog

我的其他blog

朋友的网站

搜索

  •  

最新评论

对于前个一代码这个代码加<ref bean=""/>使用和一些调试的System.out.println()从中你可以看到spring2.0的执行过程

/src/applicationContext.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"
    xsi:schemaLocation
="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

    
<bean id="strvalue" class="com.lusm.spring.test.StrValue">
        
<property name="str">
            
<value>再见了!!!</value>
        
</property>       
    
</bean>

    
<bean id="hello" class="com.lusm.spring.test.Hello" abstract="false"
        lazy-init
="default" autowire="default" dependency-check="default">
        
<property name="str">
            
<value>你好啊!!!</value>
        
</property>
        
<property name="sv">
            
<ref bean="strvalue" />
        
</property>
    
</bean>

</beans>

/src/com/lusm/spring/test/StrValue.java

package com.lusm.spring.test;

public class StrValue {
    
    String str;
    
    StrValue()
{
        System.out.println(
"StrValue class is builded");
    }

    
    
public void SayGY(){
        System.out.println(str);
    }


    
public String getStr() {
        
return str;
    }


    
public void setStr(String str) {
        
this.str = str;
    }

}

/src/com/lusm/spring/test/Hello.java

package com.lusm.spring.test;

public class Hello {
    
private String str;
    
private StrValue sv;

    
public String getStr() {
        System.out.println(
"getStr");
        
return str;
    }


    
public void setStr(String str) {
        System.out.println(
"setStr");
        
this.str = str;
    }


    
public void sayHello() {
        System.out.println(str);
    }


    
public StrValue getSv() {
        System.out.println(
"getSv");
        
return sv;
    }


    
public void setSv(StrValue sv) {
        System.out.println(
"setSv");
        
this.sv = sv;
    }


}

/src/com/lusm/spring/test/HelloTest.java

package com.lusm.spring.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class HelloTest {

    
public static void main(String[] args) {
        ApplicationContext ac 
= new FileSystemXmlApplicationContext(
                
"/src/applicationContext.xml");

        Hello h 
= (Hello) ac.getBean("hello");

        System.out.println(h.getStr());
        h.sayHello();

        StrValue sv 
= h.getSv();
        sv.SayGY();
    }


}

执行结果

log4j:WARN No appenders could be found for logger (org.springframework.context.support.FileSystemXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.

StrValue 
class is builded
setStr
setSv
getStr
你好啊!!!
你好啊!!!
getSv
再见了!!!




地震让大伙知道:居安思危,才是生存之道。
posted on 2007-09-13 23:00 小寻 阅读(398) 评论(0)  编辑  收藏 所属分类: j2se/j2ee/j2me

只有注册用户登录后才能发表评论。


网站导航: