Chinaunix首页 | 论坛 | 博客
  • 博客访问: 483750
  • 博文数量: 1496
  • 博客积分: 79800
  • 博客等级: 大将
  • 技术积分: 9940
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-09 13:22
文章分类

全部博文(1496)

文章存档

2011年(1)

2008年(1495)

我的朋友

分类:

2008-09-09 17:11:21

   Spring2.5
                   Foo.java FooStringname.
                  package com.tony.test;
    publicclass Foo {
            private String name;
                public String toStirng(){
                   return"Foo Name is :" + this.name;
                }
    Setget
    }
    2 Bar.java BarStringadd.
    package com.tony.test;
    publicclass Bar {
            private String add;
                public String toStirng(){
                   return"Bar Add is :" + this.add;
                }
    Setget
    }
    3 Main.java MainFooBar
    package com.tony.test;
    publicclass Main {
            private Foo foo;
            private Bar bar;
                public String toString(){
    return"Main : [" + this.foo.toStirng() +" "+ this.bar.toStirng() + "]";
                }
    Setget
    }
    4 Spring-config-beans.xml
           
              
              
           

           
              
           

           
              
   

    5 Test.java TestSpringmain
    package com.tony.test;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.
    ClassPathXmlApplicationContext;
    publicclass Test {
                publicstaticvoid main(String[] args) {
                     String[] locations = {"spring-config-beans.xml"};
    ApplicationContext ctx = new ClassPathXmlApplicationContext(locations);
                     Main main = (Main) ctx.getBean("main");
                     system.out.println(main);
                }
    }
    Test
    Main : [Foo Name is :Foo Bar Add is :Bar]
    1)Spring 2.5 package com.tony.test;

    import org.springframework.beans.factory.annotation.Autowired;

    publicclass Main {
               @Autowired
               private Foo foo;
               @Autowired
               private Bar bar;

               public String toString(){
 

[1]   

【责编:landy】

--------------------next---------------------

阅读(114) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~