分类:
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]