Spring介绍
来源:互联网 发布:linux time sys user 编辑:程序博客网 时间:2024/06/07 06:16
Spring官网查找jar包下载地址说明:http://blog.csdn.net/frankarmstrong/article/details/69808813
下面这个地址为4.1.6的spring jar包下载地址:
https://repo.spring.io/webapp/#/artifacts/browse/tree/General/libs-release-local/org/springframework/spring/4.1.6.RELEASE/spring-framework-4.1.6.RELEASE-dist.zip
可对照官方jar包里的文档进行相关Spring配置
一.Spring简介
Spring是一个轻量级框架,是一个IOC容器(控制反转),支持AOP面向切面编程,对事务的支持,对框架的支持(整合现有的一些框架),支持WebSocket编程等。
二.IOC容器(Inversion of control)控制反转-Spring核心功能
特点:
(1) 对象由原来程序本身来创建,变为了程序来接收对象
(2)程序主要集中于业务的实现
(3)实现了service层和dao层的解耦工作,实现分离,没有直接依赖关系。
(4)如果dao的实现发生改变,应用程序本身不用改变,不需要去关心它的具体实现。
(5)Spring容器可以通过xml或注解配置来创建对象,对象属性是由Spring容器来设置的---->这个过程就叫控制反转
控制:指谁来控制对象的创建,传统的程序是由程序本身来new创建的,利用Spring后是由Spring容器来创建的,实现分离解耦,专注业务的开发
反转:以前程序本身创建对象,变为了程序来接收Spring创建对象,权限发生了变化
正转:程序本身创建对象
依赖注入:通过set方法依赖注入(dependency injection)
以下示例展示了Spring如何通过xml创建对象
Hello.javapublic class Hello {private String name; public String getName() { return name; } public void setName(String name) { this.name = name; }}
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-3.1.xsd"default-lazy-init="true"><bean name="hello" class="HelloDemo.Hello"> <property name="name" value="张三" ></property> </bean></beans>
Test.java
package HelloDemo;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class Test {/** * main函数. * * @param args * 启动参数 * @throws Exception * Exception */public static void main(String... args) throws Exception {ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");Hello hello =(Hello) ctx.getBean("hello");System.out.println(hello.getName());}}总结:IOC是一种编程思想,由BeanFactory创建对象。
二. AOP(Aspect Oriented Programming)
AOP:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术,对于后期修改共通业务特别便捷
主要应用场景:日志记录,异常处理,安全控制(如安全检验),性能统计,事务处理,缓存刷新等
AOP实现方式:
预编译:Aspect J
运行期动态代理:如JDK动态代理,CGLib动态代理(这边这个我也不清楚,有待研究)
AOP相关概念:
Advice的类型:
Spring的AOP侧重于一种AOP实现和IOC容器的整合,提供对AspectJ的支持。有接口默认使用JAVA SE的动态代理来作为AOP代理
用@Aspect注解的类可以被Spring自动识别和管理,但是不能够通过类路径自动检测发现,需要使用@Component注释
Spring AOP实际应用场景分析:https://segmentfault.com/a/1190000007469982
- Spring 介绍
- Spring介绍
- spring 介绍
- spring介绍
- Spring介绍
- spring介绍
- spring介绍
- spring介绍
- spring介绍
- Spring介绍
- Spring介绍
- Spring 介绍
- spring介绍
- Spring 介绍
- Spring 介绍
- spring介绍
- Spring介绍
- Spring介绍
- Ubuntu14.04:如何建立手机也能连上的wifi热点
- xampp中集成的数据库MariaDB中文乱码问题
- [自用门户] 自适应站点
- gridview只显示一行的问题
- ASP.NET MVC4 自定义权限(角色)验证
- Spring介绍
- 以太网学习记录(一)
- Math
- 【EXCEL】VBAEN32.OLB丢失或损坏问题修复
- 进程间通信(1)-有名管道
- 智慧城市建设,云坤疯狂为你打call~
- 项目报错“JavaServer Faces 2.2 can not be installed : One or more constraints”等一系列问题
- 【Java笔记3.5.1】自动类型转化
- IntelliJ IDEA Maven Gradle的配置