Spring overview and completion of Hello world !, Springhello
1 Spring Overview
① Spring is an open-source framework
② Spring was born to simplify enterprise-level development. With Spring, JavaBean can implement many functions that were previously implemented by EJB. The same function can be implemented through tedious configuration and complex code in EJB, but it is very elegant and concise in Spring.
③ Spring isIOC(DI) andAOPContainer framework.
④ Excellent Spring features
[1]Non-Intrusive: Objects in applications developed based on Spring can be independent of Spring APIs (non-instrusive)
[2]Dependency Injection: DI -- Dependency Injection: the most classic Implementation of Reverse Control (IOC.
[3]Aspect-Oriented Programming: Aspect Oriented Programming -- AOP
[4]Container: Spring is a container because it contains and manages the lifecycle of application objects.
[5]Componentization: Spring combines simple component configurations into a complex application. In Spring, you can use XML and Java annotations to combine these objects.
[6]All-in-One: On the basis of IOC and AOP, You can integrate open-source frameworks and excellent third-party libraries for various enterprise applications (in fact, Spring itself also provides SpringMVC at the presentation layer and Spring JDBC at the persistence layer ).
⑤ Current Spring version
⑥ Spring Module
2. Install the Spring plug-in
Plug package: springsource-tool-suite-3.4.0.RELEASE-e4.3.1-updatesite.zip
② Operation steps: See References: springplug-in installation illustration. pptx
3. Set up the Spring Runtime Environment
① Add a JAR package
[1] Spring JAR package: spring-framework-4.0.0.RELEASE \ libs directory
Spring-beans-4.0.0.RELEASE.jar
Spring-context-4.0.0.RELEASE.jar
Spring-core-4.0.0.RELEASE.jar
Spring-expression-4.0.0.RELEASE.jar
[2] commons-logging-1.1.1.jar
② Create a Spring configuration file as needed
4 HelloWorld
① Purpose: Create an object using Spring and assign a value to the attribute
② Create a Student class
③ Create a Spring configuration file
|
<! -- Use the bean element to define an object created by the IOC container -->
<! -- Class attribute specifies the full class name used to create the bean -->
<! -- Id attribute specifies the id used to reference the bean instance -->
<! -- Use the property sub-element to assign values to bean properties -->
<Bean id ="Student"Class ="Com. atguigu. helloworld. bean. Student">
<Property name ="StudentId"Value ="1001"/>
<Property name ="StuName"Value ="Tom2015"/>
<Property name ="Age"Value ="20"/>
</Bean> |
④ Test: Create a Student class instance through the Spring IOC container
|
// 1. Create an IOC container object
ApplicationContext iocContainer =
NewClassPathXmlApplicationContext ("helloworld. xml ");
// 2. Obtain the bean Instance Object Based on the id value
Student student = (Student) iocContainer. getBean ("student ");
// 3. Print bean
System.Out. Println (student ); |
⑤ Verification: Spring has completed bean creation and attribute assignment when creating an IOC container object.