Spring Framework
The Spring framework is a lightweight container that can be used in combination with many Web applications such as struts and webwork, or it can be used alone.
First, the characteristics of spring:
Face Tangent (aspect-oriented programming AOP), control rollover (inversion of control IOC)
Lightweight: Not dependent on other objects, used alone
Container: Set declaration period and configuration in XML
Framework: Objects in the system are combined by an XML file configuration
The spring framework consists of 7 parts.
Factory mode: A class has a lot of subclasses, similar to Singleton,
Core container: Contains beanfactory to create beans, implement IOC
Application Context module: Custom Service interface, expanded Beanfactory, added support for i18n (internationalization), System lifecycle events and validations, and provided many enterprise-class services such as e-mail services. Jndi access, EJB integration, remote invocation and timer services, and support for integration with template frameworks.
AOP modules: Provides rich support for facets, is the basis for spring application development facets, and introduces metadata programming
JDBC and DAO Modules:
O/R mapping module:
Web module: Based on the application context module, provides the context of the appropriate Web system, in addition, the high module supports a number of web-oriented tasks, such as transparent processing can smell upload requests, automatically bind the request parameters in the large language object, and so on.
MVC module:
All modules are built on top of the core module container, and the container specifies how to create, configure, and manage beans, as well as other details
Third, Experience Spring (myeclipse)
1), first build the development environment
Using the jar files required by spring
Enter Http://www.springsource.org/download official website
In general, use a minimum of two jar packages, Spring.jar and Commons-logging.jar, to build the two packages into the project.
2), creating Java Classes
Create an interface first
Public interface Greetingservice {
Defining methods in an interface
public void saygreeting ();
}
Create a class that inherits the interface above
public class Greetingserviceimpl implements Greetingservice {
To define a private variable, you must have a set method for the variable
Private String say;
public void Setsay (String say) {
This.say = say;
}
Overriding methods of the parent class
@Override
public void saygreeting () {
TODO auto-generated Method Stub
SYSTEM.OUT.PRINTLN ("I said:" +say);
}
}
Then create a class that inherits the above interface
public class GREETINGSERVICEIMPL2 implements greetingservice{
Defining your own private variable, unlike the one above, is the object of a class, and it must also have a set method
Private Greetingserviceimpl GSI;
public void Setgsi (Greetingserviceimpl gsi) {
This.gsi = GSI;
}
Overriding methods of the parent class
@Override
public void saygreeting () {
TODO auto-generated Method Stub
Gsi.saygreeting ();
}
}
3), and then configure in XML, the Bean in XML is the Java class
<?xml version= "1.0" encoding= "UTF-8"?>
<beans xmlns= "Http://www.springframework.org/schema/beans"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
xmlns:context= "Http://www.springframework.org/schema/context"
xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-2.5.xsd
Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd ">
<!--the first class, the ID is the unique identifier in the XML, and class is the path to the class--
<bean id= "Greetingserviceimpl" class= "Cn.csdn.service.GreetingServiceImpl" >
<!--set the value of a property in the first class-
<property name= "say" value= "Hello" ></property>
</bean>
<!--set up Type II--
<bean id= "greetingServiceImpl2" class= "CN.CSDN.SERVICE.GREETINGSERVICEIMPL2" >
<!--set the properties of the second class, because it is the object of the class, to use the ref--
<property name= "GSI" ref= "Greetingserviceimpl" ></property>
</bean>
</beans>
4), set up JUnit class test
public class Testspring {
@Test
Public