涓婁竴綃囨枃绔?/a>浠嬬粛浜嗗浣曞湪Eclipse涓婁嬌鐢℉ibernate鐨勫叆闂紝鏈枃灝辯畝鍗曚粙緇嶄竴涓嬪浣曞湪Eclipse浣跨敤Spring銆?br />
錛?錛夐鍏堬紝鏄笅杞絊pring錛屽彲浠ヤ粠sourceforge涓婁笅杞斤紝http://sourceforge.net/projects/springframework銆傜洰鍓嶇殑鏈鏂扮殑鍙互涓嬭澆 spring-framework-1.2.8-with-dependencies.zip 銆?br />
錛?錛夌劧鍚庯紝鍙互灝哠pring寮曞叆鍒頒綘鐨勯」鐩腑銆?br />
鍏堝皢spring-framework-1.2.8-with-dependencies.zip瑙e帇錛屽皢鍏朵腑鐨剆pring.jar錛坉ist鐩綍涓級銆乧ommons-logging.jar錛坙ib\jakarta-commons鐩綍錛夈乴og4j-1.2.13.jar錛坙ib\log4j鐩綍錛夎繖涓変釜鏂囦歡澶嶅埗鍒扮殑”D:\java\Spring\lib" 鐩綍涓紝鐒跺悗鍦‥clipse涓緩绔嬩竴涓?#8220;Spring”搴擄紝灝嗛偅涓変釜鏂囦歡娣誨姞榪?#8220;Spring”搴撲腑銆?br />
錛?錛夋祴璇曚竴涓嬶細
鏂板緩涓や釜綾伙紝Student鍜孊ook銆?br />
public class Book
{
private int id = 0 ;
private String bookName ;
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
public class Student
{
private int age = 0;
private String name ;
private Book book ;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Book getBook() {
return book;
}
public void setBook(Book book) {
this.book = book;
}
public String GetBookName()
{
return this.book.getBookName() ;
}
}
鐒跺悗娣誨姞Spring閰嶇疆鏂囦歡bean.xml錛坆ean.xml蹇呴』鍦–LASSPATH鍙互瀛樺彇鍒扮殑鐩綍涓級錛?br />
<?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="student" class="com.springTest.Student">
<property name="age">
<value>22</value>
</property>
<property name="name">
<value>Sky</value>
</property>
<property name="book" ref="book">
</property>
</bean>
<bean id="book" class="com.springTest.Book">
<property name="id">
<value>1000</value>
</property>
<property name="bookName">
<value>鎴樹簤涓庡拰騫?/span></value>
</property>
</bean>
</beans>
鏈鍚庣殑涓葷▼搴忥細
public static void main(String[] args)
{
Resource res = new ClassPathResource("bean.xml");
BeanFactory factory = new XmlBeanFactory(res);
Student stu = (Student) factory.getBean("student");
System.out.println(stu.GetBookName());
}
榪愯鍚庡彲浠ョ湅鍒版帶鍒跺彴杈撳嚭錛嶏紞“鎴樹簤涓庡拰騫?#8221;銆?br />
涓嶴pring.net鐨勪嬌鐢ㄥ熀鏈畬鍏ㄤ竴鑷達紙鍖呮嫭閰嶇疆鏂囦歡銆丅eanFactory鐨勮幏鍙栫瓑錛夛紝鎵浠ョ啛鎮塖pring.net鐨勪綘榪囨浮鍒癝pring鏄潪甯稿鉤婊戠殑銆?br />
鏈鍚庯紝Java涓殑灞炴у疄鍦ㄦ槸娌℃湁C#涓殑綆媧侊紝鍛靛懙銆?br />

]]>