First, Spring
1. Concept:
Container: A container can load objects, instantiate objects, and configure dependencies between objects.
Ioc/di
Ioc:inversion of control (inversion of controls) refers to dependencies between programs that depend on a specific implementation (such as DISKUSB,UUSB) and become dependent on the abstract interface (USB).
Bottom line: dependency abstraction is not concrete .
Di:dependency Injection (Dependency injection) means that the dependencies between programs are injected dynamically by the container, rather than hard-coded implementations.
All the classes in spring are javabean,bean like the pillars of a necklace, and the configuration file is like a line that strings all the beads together.
Aop:aspect oriented programming (aspect-oriented programming) refers to one aspect of a program that is independently designed (such as transactions, logs, permissions, and so on).
2.Spring Introduction
(1) Provide one-stop service for enterprise-level development (integrated hibernate,spring MVC, etc.);
(2) Ioc:spring's core ideas and implementation, most of the functions are based on this;
(3) AOP: Provides three implementations of AOP technology in spring;
(4) Support for persistent claims: encapsulates the operation of JDBC;
Integrated with the popular technical framework (HIBERNATE,JDO,TOPLINK,IBATTS);
(5) Support for the Web tier:
Spring MVC;
Support for other frameworks (Struts,webwork)
(6) Integration of other frameworks and technologies:
RMI and WebService
Ejb
Jms
JavaMail
Timed Tasks and scheduling
3. Use Spring
(1) Add jar package: Spring.jar,commons-logging.jar;
(2) Create configuration file Beans.xml
<?XML version= "1.0" encoding= "UTF-8"?><!DOCTYPE Beans Public "-//spring//dtd bean//en" "Http://www.springframework.org/dtd/spring-beans.dtd "><Beans> <BeanID= "HW"class= "Com.lb.action.Test2"> < Propertyname= "Name"value= "Zhangsan" /> </Bean></Beans>
Public classTest2 {PrivateString name; PublicString GetName () {returnname; } Public voidsetName (String name) { This. Name =name; } Public voidHelloword () {System.out.println (name); } Public Static voidMain (string[] args) {//(3) obtain the Bean factory;Resource rs =NewClasspathresource ("Beans.xml"); Beanfactory BF=NewXmlbeanfactory (RS); //(4) Get the object. Test2 t2 = (Test2) bf.getbean ("HW"); //(5) calling methodT2. Helloword (); /*Test2 t2 = new Test2 (); T2.setname ("zhangsan2"); T2. Helloword ();*/ }}
Spring+hibernate+struts