1、spring贯穿了表现层,业务层,持久层
2、spring配置方式
XML配置方式
注解配置方式
java配置方式
3、系统功能分类
主业务逻辑:只有这个项目能用
系统业务逻辑:可移植到其他项目中
spring解耦主业务逻辑:IOC(控制反转)
spring解耦系统业务逻辑:AOP(切面编程)
4、spring简化企业开发,不替代他们
V->Spring MVC Service->Spring DAO->jdbc Templete
5、导入spring必须的包
comming-logging-1.2.jar
spring-beans-4.3.9.RELEASE.jar
spring-aop-4.3.9.RELEASE.jar
spring-context-4.3.9.RELEASE.jar
spring-core-4.3.9.RELEASE.jar
spring-expression-4.3.9.RELEASE.jar
6、Spring配置文件beans.xml头部配置解释
解释:
(1)【xmlns="http://www.springframework.org/schema/beans"】
声明xml文件默认的命名空间,表示未使用其他命名空间的所有标签的默认命名空间。
(2)【xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"】
声明XML Schema实例,声明后就可以使用schemaLocation属性。
(3)【xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd】
指定Schema的位置这个属性必须结合命名空间使用。这个属性有两个值,第一个值表示需要使用的命名空间。第二个值表示供命名空间使用的XML schema的位置。
上面配置的命名空间指定xsd规范文件,这样你在进行下面具体配置的时候就会根据这些xsd规范文件给出相应的提示,比如说每个标签是怎么写的,都有些什么属性是都可以智能提示的,在启动服务的时候也会根据xsd规范对配置进行校验。
配置技巧:对于属性值的写法是有规律的,中间使用空格隔开,后面的值是前面的补充,也就是说,前面的值是去除了xsd文件后得来的。
7、(1)导包
(2)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">
<bean id="student" class="com.anbow.study.Student"></bean>
</beans>
(3)Student.class
package com.anbow.study;
public class Student {
public void display() {
System.out.println("Hello world!");
}
}
(4)T01.class
package com.anbow.study;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class T01 {
public static void main(String[] args) {
ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
Student student=context.getBean("student",Student.class);
student.display();
}
}