Spring的大框架
初识Spring:
Spring作者:Rod Johnson
Spring框架由20个模块组成,这些模块分成六个部分,分别是Core Container,Data Access/Integration,Web,AOP,Instrumentation和Test.
Spring Core是框架的最基础的部分,提供了IoC特性。Spring Context为企业级开发提供了遍历和集成的工具。
Spring Aop是基于Spring Core的符合规范的切面编程的实现
Spring JDBC提供了提供了JDBC的抽象层,简化了JDBC编码
Spring ORM对市面上流行的ORM框架提供了支持
Spring Web为Spring在Web应用程序中的使用提供了支持
Spring 体系结构图:

最基础部分========Spring IoC
控制反转 (依赖注入) 面向对象编程的一种设计理念,降低程序代码之间的耦合度
先定义持久化方法:
public interface IUserBiz {
//隔离的作用
public void save(User user);
}
实现对User类的持久化操作
public class UserBiz implements IUserBiz {
private IDao dao;
public void save(User user) {
dao.save(user);
}
public void setDao(IDao dao) {
this.dao = dao;
}
}
用户业务类,实现对User功能的业务管理
public class UserServiceImpl implements UserService
{ private UserDao dao=new UserDaoImpl();
public void addNewUser(User user){
dao.save(user);
} }
bean文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
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
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!--IOC-->
<bean id="happyService" class="cn.zixin.service.HappyService">
<!--DI 依赖注入-->
<property name="info" value="Spring"></property>
</bean> <!--准备一个彩色墨盒-->
<bean id="colorInk" class="cn.zixin.printer.ink.GrayInk"></bean>
<!--准备一个B5纸-->
<bean id="B5paper" class="cn.zixin.printer.paper.A5Paper"></bean>
<!--准备打印机-->
<bean id="printer" class="cn.zixin.printer.print.Printer">
<property name="ink" ref="colorInk"></property>
<property name="paper" ref="B5paper"></property> </bean> <!--dao-->
<bean id="UserDao" class="cn.zixin.aop.UserDao"></bean>
<!--service-->
<bean id="UserBiz" class="cn.zixin.aop.service.UserBiz">
<property name="dao" ref="UserDao"></property>
</bean>
<!--增强配置-->
<!--前置配置-->
<bean id="LoggerAfter" class="cn.zixin.aop.LoggerAfter"></bean>
<!--后置配置-->
<bean id="LoggerBefore" class="cn.zixin.aop.LoggerBefore"></bean> <!--Aop配置-->
<aop:config>
<aop:pointcut id="pointcut" expression="execution(* *..service.*.*(..))"></aop:pointcut>
<aop:advisor advice-ref="LoggerAfter" pointcut-ref="pointcut"/>
<aop:advisor advice-ref="LoggerBefore" pointcut-ref="pointcut"/>
</aop:config>
</beans>
使用<BEAN>的一个组件时 ---------- id用来访问的唯一名称 name属性指定
测试类:
package cn.zixin.test; import cn.zixin.aop.User;
import cn.zixin.aop.service.IUserBiz;
import cn.zixin.printer.print.Printer;
import cn.zixin.service.HappyService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; /**
* Created by benxin on 2017/7/22.
*/
public class FirstSpringTest { @Test
public void firstTest(){
ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
HappyService service=(HappyService) context.getBean("happyService");
service.work();
}
@Test
public void firstTests(){
ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
Printer printer = (Printer) context.getBean("printer");
printer.print();
}
@Test
public void aop() {
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
IUserBiz biz=(IUserBiz)ctx.getBean("UserBiz");
User user=new User();
biz.save(user);
System.out.println("success!");
}
}
Spring的大框架的更多相关文章
- 3大框架Struts、Hibernate、Spring简单了解
3大框架:Struts.Hibernate.Spring 基本概念:Spring/Struts/Hibernate是干嘛用的? 三个框架产生的技术历史背景 学习前首先应该掌握的基础知识 学习一个开发框 ...
- 为什么做java的web开发我们会使用struts2,springMVC和spring这样的框架?
今年我一直在思考web开发里的前后端分离的问题,到了现在也颇有点心得了,随着这个问题的深入,再加以现在公司很多web项目的控制层的技术框架由struts2迁移到springMVC,我突然有了一个新的疑 ...
- Struts,spring,hibernate三大框架的面试
Struts,spring,hibernate三大框架的面试 1.Hibernate工作原理及为什么要用? 原理: 1.读取并解析配置文件 2.读取并解析映射信息,创建SessionFactory 3 ...
- Spring的JDBC框架
转自: http://www.cnblogs.com/windlaughing/p/3287750.html Spring JDBC提供了一套JDBC抽象框架,用于简化JDBC开发. Spring主要 ...
- Spring Batch 批处理框架
<Spring Batch 批处理框架>基本信息作者: 刘相 出版社:电子工业出版社ISBN:9787121252419上架时间:2015-1-24出版日期:2015 年2月开本:16开页 ...
- 图书简介:Spring Batch批处理框架
大数据时代批处理利器,国内首度原创解析Spring Batch框架. 内容简介: <Spring Batch 批处理框架>全面.系统地介绍了批处理框架Spring Batch,通过详尽的实 ...
- 为什么使用spring Struts 等框架开发
转载自:http://www.cnblogs.com/sharpxiajun/p/3936268.html 今年我一直在思考web开发里的前后端分离的问题,到了现在也颇有点心得了,随着这个问题的深入, ...
- Struts2+Spring+Hibernate 三大框架的合并集成
这次来看看Struts2+Spring+Hibernate三大框架的整合应用,主要是Spring和Hibernate框架的整合,因为前边已经将Strtus2+Spring整合过了基本一样. 首先看一 ...
- SSM(Spring + Springmvc + Mybatis)框架面试题
JAVA SSM框架基础面试题https://blog.csdn.net/qq_39031310/article/details/83050192 SSM(Spring + Springmvc + M ...
随机推荐
- POJ 2239
#include<iostream> #include<algorithm> #define MAXN 305 using namespace std; int _m[MAXN ...
- (C/C++) FILE 讀寫檔案操作
在C/C++ 讀寫檔案操作比較常見應該是利用 FILE.ifstream.ofstream 在這篇筆記裡頭記錄 FILE.fstream 使用方法及操作 #include <iostream&g ...
- 关于nginx的一个错误操作记录
今天在弄前后端同步的测试的时候,前端用Nginx代理访问后端接口,由于启动了多次nginx软件,没有将前几次启动的nginx进程关闭,导致在访问后端接口的request被挂起,过了半天也没有结果返回, ...
- Java NIO学习与记录(五): 操作系统的I/O模型
操作系统的I/O模型 在开始介绍NIO Reactor模式之前,先来介绍下操作系统的五种I/O模型,了解了这些模型,对理解java nio会有不小的帮助. 先来看下一个服务端处理一次网络请求的流程图: ...
- vsftpd文件虚拟用户搭建
关于vsftpd的原理这里就不多说了,下面红色部分有单独标出,突出显示,意思是这里的东西有额外的配置,全文的配置一定要跟着第二步的配置来,不要过程中随便改变参数,除非你看得懂,好了直接上配置过程 1. ...
- php 如何截取中文字符串
在网站应用中时常需要对相应的字符串进行截取.最常用的是使用substr函数对字符串进行截取. 然而,substr和strlen函数只在处理英文字符串时可以正确使用,在截取中文字符时,时常出现乱码.这时 ...
- 【Kafka】Consumer配置
从0.9.0.0开始,下面是消费者的配置. 名称 描述 类型 默认值 bootstrap.servers 消费者初始连接kafka集群时的地址列表.不管这边配置的什么地址,消费者会使用所有的kafka ...
- Springboot用官方建议访问Html页面并接传值
Springboot用官方建议访问Html页面并接传值 我们以前通常习惯用webapp来防止jsp页面,但是到了Springboot中,官方建议用Static文件夹来存放及静态的资源, 用templa ...
- git提交代码到远程仓库
1.仓库初始化 git init 2.连接仓库 git remote add origin 仓库地址 3.查看状态 git status 4.将文件添加到暂存区 git add 状态里的新文件 5.将 ...
- Golang之并发资源竞争(互斥锁)
并发本身并不复杂,但是因为有了资源竞争的问题,就使得我们开发出好的并发程序变得复杂起来,因为会引起很多莫名其妙的问题. package main import ( "fmt" &q ...