The vs.net+spring.net+nhibernate used on. NET, on the Java platform, naturally corresponds to the eclipse+spring+hibernate. The previous article describes how to get started with hibernate on Eclipse, and this article briefly describes how to use spring in eclipse.
(1) First, the download spring, can be downloaded from SourceForge, http://sourceforge.net/projects/springframework. Currently the latest can be downloaded spring-framework-1.2.8-with-dependencies.zip.
(2) You can then bring spring into your project.
First extract the Spring-framework-1.2.8-with-dependencies.zip, the Spring.jar (dist directory), Commons-logging.jar (lib\ Jakarta-commons directory), Log4j-1.2.13.jar (lib\log4j directory), the three files copied to the "D:\java\Spring\lib" directory, and then create a "Spring" library in Eclipse, Add the three files into the Spring library.
(3) Test:
Create a new two class, student and book.
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.) {
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 ();
}
}
Then add the spring configuration file Bean.xml (Bean.xml must be in the directory that Classpath can access):
<?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> War and Peace </value>
</property>
</bean>
</beans>
The final main program:
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 ());
}
After running, you can see the console output-"war and Peace."
The use of spring.net is basically exactly the same (including configuration files, beanfactory acquisition, etc.), so it is very smooth for you to be familiar with the spring.net of your transition to spring.
Finally, the attributes in Java are not simple in C #, hehe.
From:http://www.cnblogs.com/zhuweisky/archive/2006/05/30/413370.html
Java--using spring on eclipse