注入

  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注入的更多相关文章

  1. Spring.NET依赖注入框架学习--简单对象注入

    Spring.NET依赖注入框架学习--简单对象注入 在前面的俩篇中讲解了依赖注入的概念以及Spring.NET框架的核心模块介绍,今天就要看看怎么来使用Spring.NET实现一个简单的对象注入 常 ...

  2. Spring IOC 注入方式

    依赖注入通常有如下两种方式: ①设值注入:IOC容器使用属性的Setter方法来注入被依赖的实例. 设值注入是指IOC容器使用属性的Setter方法来注入被依赖的实例.这种注入方式简单.直观,因而在S ...

  3. Spring的IoC容器注入的类型

    Spring除了可以注入Bean实例外,还可以注入其他数据类型. 注入基本数据类型 xml配置文件中的init-method="init"属性是取得Bean实例之后,输入属性值后自 ...

  4. spring框架--IOC容器,依赖注入

    思考: 1. 对象创建创建能否写死? 2. 对象创建细节 对象数量 action  多个   [维护成员变量] service 一个   [不需要维护公共变量] dao     一个   [不需要维护 ...

  5. Spring IOC 注入方式详解 附代码

    引言 Spring框架作为优秀的开源框架之一,深受各大Java开发者的追捧,相信对于大家来说并不陌生,Spring之所以这么流行,少不了他的两大核心技术IOC和IOP.我们这里重点讲述Spring框架 ...

  6. Spring实现Ioc的多种方式--控制反转、依赖注入、xml配置的方式实现IoC、对象作用域

    Spring实现Ioc的多种方式 一.IoC基础 1.1.概念: 1.IoC 控制反转(Inversion of Control) IoC是一种设计思想. 2.DI 依赖注入 依赖注入是实现IoC的一 ...

  7. Spring-初识Spring框架-IOC控制反转(DI依赖注入)

    ---恢复内容开始--- IOC :控制反转 (DI:依赖注入)使用ioc模式开发 实体类必须有无参构造方法1.搭建Spring环境下载jarhttp://maven.springframework. ...

  8. Spring扩展:Spring的IoC容器(注入对象的方式和编码方式)

    二.Spring的IoC容器 IoC:Inversion of Control(控制反转) DI:Dependency Injection(依赖注入) 三.依赖注入的方式 (1)构造注入 (2)set ...

  9. Spring.net Ioc 依赖注入

    控制反转 (Inversion of Control,英文缩写为IoC)是一个重要的面向对象编程的法则来削减计算机程序的耦合问题,也是轻量级的Spring框架的核心. 控制反转一般分为两种类型,依赖注 ...

随机推荐

  1. Windows系统下安装zabbix客户端

    简单介绍如何在windows系统下安装zabbix客户端 1. 首先下载和zabbix服务端大版本相同的windows客户端    例如我服务端安装的是zabbix-3.4.14.tar.gz     ...

  2. [U3D Demo] 手机飞机大战

    游戏截图 使用插件 DOTween NGUI 游戏介绍 游戏使用C#开发,素材是<全民飞机大战>中提取出来的,该游戏最早是去年由Flash Air+Starling开发的Demo,后来我修 ...

  3. js判断移动端是否安装某软软件,安装直接打开相应的链接,否则跳转到下载商店方法

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  4. 我们为什么要在Android中使用RxJava

    本文翻译来自–>Why should we use RxJava on Android 另外: 微凉一季 再另外: 微凉一季 感觉RxJava近期风生水起,不学习一下都不好意思了.洒家也是初学R ...

  5. hdoj:2052

    #include <iostream> #include <string> using namespace std; int main() { int n, m; while ...

  6. bootstrap动态添加Tab标签页

    好久没有写博客了(主要是懒),工作中用到一个动态添加Tab的功能,众所周知,bootstrap没有动态添加Tab的功能,网上又没找到什么好用的,那咱就自己写呗?(因为懒,所以只写了添加的方法.(๑&g ...

  7. HDFS: The short-circuit local reads feature cannot be used

    问题: method:org.apache.hadoop.hdfs.DomainSocketFactory.<init>(DomainSocketFactory.java:69) The ...

  8. Beautiful Soup模块

    Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库,它能够通过你喜欢的转换器实现惯用的文档导航,查找,修改文档的方式.Beautiful Soup会帮你节省数小时 ...

  9. Windows 安装服务 的两种方式

    第一种   -  安装服务时自定义服务名称:(注意 binpath= 和路径之间的那个空格)sc create 服务名称  binpath= "D:\Service.exe" di ...

  10. SVD与SVD++

    参考自:http://blog.csdn.net/wjmishuai/article/details/71191945 http://www.cnblogs.com/Xnice/p/4522671.h ...