Preparing the environment:
Download zip package: https://spring.io/tools3/sts/all/ zip package downloaded from the following
Plug Help ==> Install New SoftWare
Click on the following zip package after the Archive download a good choice
Can be selected as follows
Then the back of the consent agreement or something all the way next to the last finish
Then in the bottom right corner of the window a progress bar to install plug-in, waiting for pop. Finally, you will be asked to restart the eclipse. It can restart.
window ==> preference can see already installed in the following figure
The Hello World Spring Case:
You need five jar package:
- commons-logging
- spring-beans
- spring-context
- spring-core
- spring-expresso
- Download spring need to use the zip package: https://repo.spring.io/release/org/springframework/spring/
Which contains a spring-beans, spring-context, spring-core, spring-expresso four jar package
- commons-logging: Download
Then copied to the project src / lib Build Path and add to jar library project
The following is added after the project is good
- Creating the HelloWorld objects
HelloWorld.java
public class HelloWorld { private String name; public void setName(String name) { this.name=name; } public void hello() { System.out.println("hello "+name); } }
- Creating springIOC container in the configuration file src applicationContext.xml
In <beans> </ beans> tag added <bean> </ bean> tag is as follows<!-- helloworldBean配置 --> <bean id="helloWorld" class="com.taotao.beans.HelloWorld"> <property name="name" value="spring" ></property> </bean>
- Main function call three steps:
//获取spring ioc容器(从配置的xml文件中获取)
ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
//获取bean
HelloWorld helloWorld=(HelloWorld)ctx.getBean("helloWorld");
//调用hello方法
helloWorld.hello();
You can execute the main method
Screenshot analysis code :( enlarged view)