http://mvnrepository.com/artifact/org.springframework
or
http://sourceforge.net/projects/springframework/files/
裡面包含單一檔案 和 整合(spring-full)版本
DTD檔下載位置
http://www.springframework.org/dtd/
bean.xml 抬頭設置
簡易範例:
---SpringTest.java
package spring001;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class SpringTest {
public static void main(String[] args) {
ApplicationContext ctx = new FileSystemXmlApplicationContext("src\\bean.xml");
person p = null;
p = (person)ctx.getBean("chinese");
System.out.println(p.sayHello("acc"));
System.out.println(p.sayGoodbye("acc"));
p = (person)ctx.getBean("english");
System.out.println(p.sayHello("acc"));
System.out.println(p.sayGoodbye("acc"));
}
}
--English.java
package spring001;
public class English implements person {
@Override
public String sayHello(String name) {
return name + ",Hello!!!";
}
@Override
public String sayGoodbye(String name) {
return name + ",Good bye!!!";
}
}
--Chinese.java
package spring001;
public class Chinese implements person {
@Override
public String sayHello(String name) {
return name + ",哈囉!!!";
}
@Override
public String sayGoodbye(String name) {
return name + ",再見!!!";
}
}
--person.java
package spring001;
public interface person {
public String sayHello(String name);
public String sayGoodbye(String name);
}
--bean.xml 放置在src目錄下
沒有留言 :
張貼留言