Eclipse creates a spring project
First, build Spring project: Open Eclipse, create a new project File->new->project
Select Web->dynamic Web Project
Click Next, and then the following image appears, Project name to pick it up, for later convenience, this is called KJSB
After clicking Finish, right-click on the Fuckspring project and new->folder a folder named Lib
Now go to the extracted Spring folder and find a file spring-framework-2.5.6-with-dependencies\spring-framework-2.5.6\lib\jakarta-commons\ Commons-logging.jar
and Spring-framework-2.5.6\dist\spring.jar
Copy the Commons-logging.jar and Spring.jar into the Lib folder that was just built (although I read the book for a day, but I think it is not directly referenced because of the relative path and the absolute path, it is easy to post later)
Add a reference to eclipse. Right-click on the Fuckspring project and select Properties to appear as shown:
Choose Java Build Path on the left, select libraries in the middle, and add Library to the right. Then select User Libaries->new in the pop-up box and name it, such as librariesforfuckspring, and then OK. In the following screen, select Librariesforfuckspring, click Add JARs
Refer to the following Commons-logging.jar and Spring.jar in the Lib folder. When it's done, it's like this:
Second, create the spring configuration file:
Right-click on SRC in Java resources, new->other->xml->xml file New name Hello.xml
The code is as follows:
<?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= "Mybean" class= "Com.hisoft.test.HelloTest" >
<property name= "Hello" >
<value>hello World!!! </value>
</property>
</bean>
</beans>
On the SRC new class his package is named: com.hisoft.test, Name: springtest
The code for Springtest.java is as follows:
Import Org.springframework.context.ApplicationContext;
Import Org.springframework.context.support.FileSystemXmlApplicationContext;
public class Springtest {
Private String Hello;
Public String Gethello () {
return hello;
}
public void Sethello (String hello) {
This.hello = Hello;
}
public void Show () {
System.out.println ("--message--" + Gethello ());
}
public static void Main (string[] args) {
ApplicationContext CTX = new Filesystemxmlapplicationcontext (
"Src/hello.xml");
Springtest fs = (springtest) ctx.getbean ("Mybean");
Fs.show ();
}
}
Last run Springtest.java can be seen in the console
Info: Refreshing org.springframework.context.support.filesystemxmlapplicationcontext@77c118ae:display name [ ORG.SPRINGFRAMEWORK.CONTEXT.SUPPORT.FILESYSTEMXMLAPPLICATIONCONTEXT@77C118AE]; startup Date [Sat 21:42:44 CST 2014]; Root of context Hierarchy
November 15, 2014 9:42:44 pm Org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadbeandefinitions
Info: Loading XML bean definitions from file [F:\H5WS\kjsb\src\hello.xml]
November 15, 2014 9:42:44 pm Org.springframework.context.support.AbstractApplicationContext obtainfreshbeanfactory
Info: Bean factory for application context [org.springframework.context.support.filesystemxmlapplicationcontext@ 77C118AE]: org.springframework.beans.factory.support.defaultlistablebeanfactory@7305830a
November 15, 2014 9:42:44 pm org.springframework.beans.factory.support.DefaultListableBeanFactory Preinstantiatesingletons
Information: pre-instantiating singletons in org.springframework.beans.factory.support.defaultlistablebeanfactory@7305830a: defining beans [Mybean]; Root of Factory hierarchy
--message--hello World!!!
Now the Eclipse Creation Spring Project has been integrated.