注入

  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. notepad++ 复制代码--高亮 - 带颜色

    思路来源:http://blog.csdn.net/super828/article/details/72826024 选择代码,然后右键选择菜单命令

  2. Python的数据库mongoDB的入门操作

    Python代码: import pymongo # 获取本地端口,激活mongo客户端 client = pymongo.MongoClient('localhost',27017) # 创建一个数 ...

  3. Docker 版本

    1. Docker 版本 长话短说:现在Docker改为基于YY.MM的版本(像Ubuntu),用户可以选择Stable(发布较慢)或者Edge(发布较快)版本. Docker Engine改为Doc ...

  4. Atitit orm的实现模式 data-mapper模式和active-record模式有什么区别

    Atitit orm的实现模式  data-mapper模式和active-record模式有什么区别 1.1. 这是来自Node.js路线有关混合两种ORM模式Active Record(活动记录模 ...

  5. 远程调试Android手机上网页的记录

    1.手机需要开启USB调试模式: 2.电脑和手机上都要安装最新的Chrome浏览器: 3.手机连接电脑,会出现下载安装驱动的提示并安装成功(并不是所有的手机都会这么顺利,比如我的魅族就无法安装驱动,公 ...

  6. Generate google sitemap xml

    方式一. XNamespace xNamespace = "http://www.sitemaps.org/schemas/sitemap/0.9"; XNamespace xht ...

  7. ssh连接服务器失败解决记录

    故障:db2inst1用户无法通过ssh连接数据库服务器. 但是root用户可以连接,连接后su – db2inst1用户报错: su: cannot set user id: Resource te ...

  8. Ubuntu apt 使用代理

    . . . . . 由于一台 Ubuntu 主机无法直接连接外网,但同内网的另一台 Windows 主机可以连接外网,于是在 Win 主机上搭建了代理服务,使 Ubuntu 主机通过代理更新系统. 记 ...

  9. Linux服务器重启后eureka报错

    在Linux服务器重启后,首次启动应用时查看eureka注册中心,报错 EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP W ...

  10. apache2.4 httpd.conf httpd-vhost.conf配置

    extra / httpd-vhost.conf <VirtualHost *:81> DocumentRoot "/data/sda1_data/" ServerNa ...