Spring之IOC注入
注入
spring依赖注入
set方法:
<property name="属性名" values ="值">--ref="对象名"
构造方法:
<constructor-arg name="属性名" values="值">--ref="对象名"
p命名空间:
引入p命名空间的一个约束
p:属性名=值 p:属性名-ref=“值”
SPEL表达式
格式:values=#{值,对象,类.方法 ,类.属性}
复杂数据类型
数组,list <list><value>值</value></list>
Set: <set><value>值</value></set>
MAP:<entry key="值" value="值">
通知类型
前置类型:before
后置类型:after-returning
环绕类型:around
异常类型:after-throwing
最终类型:after
AOP注解方式
1.把切面类和目标类交给spring管理
2.开启组件(AOP注解):<aop:aspetj-autoproxy>
3.在切面类的方法上添加注解
SpringJDBC模板:
jdbcTemplate
实现代码:
<bean id="car" class="com.test.aop.CarInfo"></bean>
<bean id="carProxy" class="com.test.aop.CarInfoProxy"></bean>
<!-- A0P配置 -->
<aop:config>
<!-- 配置本方法需要增强的类里面的哪些方法-->
<aop:pointcut expression="execution(* com.test.aop.CarInfo.save(..))"
id="carPoincut"/>
<!-- 配置切面 增强类 -->
<aop:aspect ref="carProxy">
<!-- 前置类型 -->
<aop:before method="checkSave" pointcut-ref="carPoincut"/>
<!-- 后置类型 -->
<aop:after-returning method="late" pointcut-ref="carDelete" returning="re"/>
<!-- <aop:after method="late" pointcut-ref="carDelete"/> -->
<!-- aop:after-returning==如果发生异常就不会执行,after可以 -->
<!-- 环绕类型 -->
<aop:around method="around" pointcut-ref="carHuan"/>
<!-- 异常类型 -->
<aop:after-throwing method="exce" pointcut-ref="carex" throwing="exception"/>
<!-- 最终类型 -->
<aop:after method="fin" pointcut-ref="carAf"/>
</aop:aspect>
</aop:config>
<!-- 开启属性注解 -->
<context:annotation-config></context:annotation-config>
spring需要的约束:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
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
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
"> <!-- bean definitions here --></bean>
Spring之IOC注入的更多相关文章
- Spring.NET依赖注入框架学习--简单对象注入
Spring.NET依赖注入框架学习--简单对象注入 在前面的俩篇中讲解了依赖注入的概念以及Spring.NET框架的核心模块介绍,今天就要看看怎么来使用Spring.NET实现一个简单的对象注入 常 ...
- Spring IOC 注入方式
依赖注入通常有如下两种方式: ①设值注入:IOC容器使用属性的Setter方法来注入被依赖的实例. 设值注入是指IOC容器使用属性的Setter方法来注入被依赖的实例.这种注入方式简单.直观,因而在S ...
- Spring的IoC容器注入的类型
Spring除了可以注入Bean实例外,还可以注入其他数据类型. 注入基本数据类型 xml配置文件中的init-method="init"属性是取得Bean实例之后,输入属性值后自 ...
- spring框架--IOC容器,依赖注入
思考: 1. 对象创建创建能否写死? 2. 对象创建细节 对象数量 action 多个 [维护成员变量] service 一个 [不需要维护公共变量] dao 一个 [不需要维护 ...
- Spring IOC 注入方式详解 附代码
引言 Spring框架作为优秀的开源框架之一,深受各大Java开发者的追捧,相信对于大家来说并不陌生,Spring之所以这么流行,少不了他的两大核心技术IOC和IOP.我们这里重点讲述Spring框架 ...
- Spring实现Ioc的多种方式--控制反转、依赖注入、xml配置的方式实现IoC、对象作用域
Spring实现Ioc的多种方式 一.IoC基础 1.1.概念: 1.IoC 控制反转(Inversion of Control) IoC是一种设计思想. 2.DI 依赖注入 依赖注入是实现IoC的一 ...
- Spring-初识Spring框架-IOC控制反转(DI依赖注入)
---恢复内容开始--- IOC :控制反转 (DI:依赖注入)使用ioc模式开发 实体类必须有无参构造方法1.搭建Spring环境下载jarhttp://maven.springframework. ...
- Spring扩展:Spring的IoC容器(注入对象的方式和编码方式)
二.Spring的IoC容器 IoC:Inversion of Control(控制反转) DI:Dependency Injection(依赖注入) 三.依赖注入的方式 (1)构造注入 (2)set ...
- Spring.net Ioc 依赖注入
控制反转 (Inversion of Control,英文缩写为IoC)是一个重要的面向对象编程的法则来削减计算机程序的耦合问题,也是轻量级的Spring框架的核心. 控制反转一般分为两种类型,依赖注 ...
随机推荐
- mysql5.6 sql_mode设置为宽松模式
最近遇到一个很奇怪的事情 由于数据人员的需求,现在需要修改mysql的sql_mode sql_mode默认是sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_ ...
- vue-resource和vue-async-data两个插件的使用
vue-resource和vue-async-data两个插件的使用,看了一下文档http://cn.vuejs.org/guide/plugins.html#u5DF2_u6709_u63D2_u4 ...
- 【iCore4 双核心板_FPGA】实验十九:使用JTAT UART终端打印信息
实验指导书及源代码下载地址: 链接:https://pan.baidu.com/s/1c3mqDkW 密码:4x9h iCore4链接:
- 【gulp】gulp-file-include 合并 html 文件
gulp-file-include 是 gulp 插件,它提供了一个 include 方法让我们可以像后端模板那样把公共部分的页面导入进来. 安装依赖包(包括了 gulp-file-include 和 ...
- Centos&Redhat下bcm43142博通无线网卡linux驱动之二
上次通过更换内核实现成功编译驱动无线网卡,但是启动到系统原内核下依然没有bcm43142的驱动,遂准备在原内核下编译驱动,记录一下 ps:更推荐这种方法,避免因更换内核出现其他兼容性问题 1.准备驱动 ...
- 【转】Flask入门之上传文件到服务器
#Sample.py # coding:utf-8 from flask import Flask,render_template,request,redirect,url_for from werk ...
- final可以修饰类、属性、方法。
当用final修饰类的时候,此类不可被继承,即final类没有子类.这样可以用final保证用户调用时动作的一致性,可以防止子类覆盖情况的发生. 当利用final修饰一个属性(变量)的时候,此 ...
- 一款可视化的在线制作H5
一款可视化的在线制作H5 官方网站: http://www.iii66.cn 制作H5网址: http://www.iii66.cn/love/page/index 包括对图片,文字,图形,视频,声音 ...
- QT中事件处理器和事件过滤器实现实例
Qt中事件处理的方式,最常用的就是使用事件处理器(event handler)和事件过滤器(event filter)这两种方法.接下来,我们就来看看事件处理器和事件过滤器是怎么使用的. 事件处理器 ...
- log4j Tricks (log4j 1.2)
1. 开启 log4j 框架内部的日志输出到控制台 # 在 log4j.properties 中添加log4j.debug=true # 配置 log4j 框架内部的日志通过 System.out 输 ...