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框架的核心. 控制反转一般分为两种类型,依赖注 ...
随机推荐
- nginx伪静态配置教程总结
在nginx中配置伪静态,也就是常说的url重写功能,只需在nginx.conf配置文件中写入重写规则即可. 当然,这个规则是需要熟悉正则表达式,只掌握nginx自身的正则匹配模式即可,对正则不了解的 ...
- Delphi Format 格式化数字
Format('x=%d', [12]); //'x=12' //最普通Format('x=%3d', [12]); //'x= 12' //指定宽度Format('x=%f', [12.0]); / ...
- Linux将yum源设置为阿里云的镜像源
第一步:备份原有镜像源 mv /etc/yum.repo.d/Centos-Base.repo /etc/yum.repo.d/Centos-Base.repo.bak 第二步:下载阿里云的镜像源 w ...
- NetBeans使用Consolas中文乱码的解决
1.进入jdk安装目录下/jre/lib文件夹,找到fontconfig.properties.src,拷贝为 fontconfig.properties ,修改此文件. 找到: sequence.m ...
- maven添加jetty插件,同时运行多个实例
<plugins> <!-- jetty插件 --> <plugin> <groupId>org.eclipse.jetty</groupId&g ...
- QtCreator pro中相对路径和debug文件夹下未放动态库时调试报QtCreator:during startup program exited with code 0xc0000135错误
QtCreator pro中相对路径一般是以pro文件(非main函数所在文件)所在的当前目录为起点,用$$PWD表示. 如头文件和库文件 INCLUDEPATH +=$$PWD/inc win32 ...
- 使用SMART监控Ubuntu
参考:完全用 GNU/Linux 工作 - 29. 檢測硬碟 S.M.A.R.T. 健康狀態 1.安装 sudo apt-get install smartmontools 2.查看硬盘的参数,需要获 ...
- 终于把eShopOnContainer部署成功了。
先上图说明一下,然后把步骤一部一部写上来吧.
- jenkins 登录远程机器并执行脚本,脚本中有后台执行的程序无法执行解决方法。
jenkins构建shell执行配置 在远程shell脚本中,需要后台执行的命令需要以$( )括起来
- PHP 正则 空字符 / NUL字符
\xnn 匹配中ASCII代码十六进制代码为nn的字符.[\x00-\x7F] 匹配ASCII值从0-127的字符.0-127表示单字节字符,也就是:数字,英文字符,半角符号,以及某些控制字符. 正则 ...