Introduction to Spring
- 1) What is Spring?
Spring is a hierarchical Java SE/EE application full-stack lightweight open source framework
"full-stack
Service Dao web
"轻量级
Add modules on demand
"开源
source code can be obtained
with IOC- (Inverse Of Control: inverted control) and AOP- (Aspect Oriented Programming: aspect-oriented programming)
is the core - (2) What are the characteristics?
Provides the presentation layer SpringMVC
persistence layer Spring JDBC
can also integrate many well-known third-party frameworks and class libraries in the open source world.
Business layer transaction management AOP
facilitates decoupling and simplifies the development of IOC
Java source code is a classic learning paradigm
gradually becoming the most used Java EE enterprise application Open source framework
Spring architecture system
(1) Test
: Used for testing
(2) Core container
: The core container is used to assemble Java Bean objects
(3) AOP
: Aspect programming
(4) Aspects
: Provides integration with AspectJ
(5) Data access
: Data access. Used to access and operate our database. Support the operation of the persistence layer. jdbcTemplate mybatis
(6) Web
: used to support the data display layer, support http request
(7) Transactions
: used to support transaction processing. Used to solve the transaction processing problem of the business layer. Programmatic transaction management and declarative transaction management
Spring's IOC theory
- (1) What is IOC
Inversion of Control-(Inversion of Control, abbreviated as IoC)
"The original new object is converted into this way, spring反射
creates objects by way of
"spring created objects into a container,注入
Give it to whoever needs it- (get the object and assign it to the reference)
Simply put: give the right to create and manage objects to Spring
Spring's IOC entry-environment setup - (1) Create Project maven
- (2) Create the module module maven
- (3) Configuration dependency
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- 要让 spring容器给我创建一个person对象-->
<!-- 配置类名,用于反向创建对象-->
<!-- 同时给一个编号方便查找-->
<bean id="person" class="com.ssm.pojo.Person" >
<property name="eat" value="吃面包"></property>
<property name="wat" value="玩游戏"></property>
</bean>
</beans>
Person
package com.ssm.pojo;
public class Person {
private String eat;
private String wat;
public String getEat() {
return eat;
}
public void setEat(String eat) {
this.eat = eat;
}
public String getWat() {
return wat;
}
public void setWat(String wat) {
this.wat = wat;
}
}
TestIOC
import com.ssm.pojo.Person;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class testIoc{
@Test
public void test01(){
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
//System.out.println(applicationContext.getBean("person"));
Person person = (Person) applicationContext.getBean("person");
System.out.println(person.getEat());
}
}