Spring依赖检查
- none – 没有依赖检查,这是默认的模式。
- simple – 如果基本类型(int, long,double…)和集合类型(map, list..)的任何属性都没有设置,UnsatisfiedDependencyException将被抛出。
- objects – 如果对象类型的任何属性都没有设置,UnsatisfiedDependencyException将被抛出。
- all – 如果任何类型的任何属性都没有被设置,UnsatisfiedDependencyException将被抛出。
注:默认模式是 none
示例
package com.yiibai.common;public class Customer
{private Person person;private int type;private String action;//getter and setter methods
}
package com.yiibai.common;public class Person
{private String name;private String address;private int age;//getter and setter methods
}
1. none 依赖检查
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd"><bean id="CustomerBean" class="com.yiibai.common.Customer" ><property name="action" value="buy" /></bean><bean id="PersonBean" class="com.yiibai.common.Person"><property name="name" value="yiibai" /><property name="address" value="address ABC" /><property name="age" value="29" /></bean></beans>
2. simple 依赖检查
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd"><bean id="CustomerBean" class="com.yiibai.common.Customer" dependency-check="simple"><property name="person" ref="PersonBean" /><property name="action" value="buy" /></bean><bean id="PersonBean" class="com.yiibai.common.Person"><property name="name" value="yiibai" /><property name="address" value="address ABC" /><property name="age" value="29" /></bean></beans>
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'CustomerBean'
defined in class path resource [config/Spring-Customer.xml]:
Unsatisfied dependency expressed through bean property 'type':
Set this property value or disable dependency checking for this bean.
3. objects 依赖检查
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd"><bean id="CustomerBean" class="com.yiibai.common.Customer" dependency-check="objects"><property name="action" value="buy" /><property name="type" value="1" /></bean><bean id="PersonBean" class="com.yiibai.common.Person"><property name="name" value="yiibai" /><property name="address" value="address ABC" /><property name="age" value="29" /></bean></beans>
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'CustomerBean'
defined in class path resource [config/Spring-Customer.xml]:
Unsatisfied dependency expressed through bean property 'person':
Set this property value or disable dependency checking for this bean.
4. all 依赖检查
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd"><bean id="CustomerBean" class="com.yiibai.common.Customer" dependency-check="all"><property name="action" value="buy" /></bean><bean id="PersonBean" class="com.yiibai.common.Person"><property name="name" value="yiibai" /><property name="address" value="address ABC" /><property name="age" value="29" /></bean></beans>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd" default-dependency-check="all"><bean id="CustomerBean" class="com.yiibai.common.Customer"><property name="action" value="buy" /><property name="type" value="1" /></bean><bean id="PersonBean" class="com.yiibai.common.Person"><property name="name" value="yiibai" /><property name="address" value="address ABC" /><property name="age" value="29" /></bean></beans>
Spring依赖检查相关推荐
- Spring使用@Required注解依赖检查
Spring依赖检查 bean 配置文件用于确定的特定类型(基本,集合或对象)的所有属性被设置.在大多数情况下,你只需要确保特定属性已经设置但不是所有属性.. 对于这种情况,你需要 @Required ...
- Spring的属性依赖检查
Spring支持4种依赖检查:默认的是none none – No dependency checking. simple – If any properties of primitive type ...
- 分享Spring中Bean的4种依赖检查模式
http://developer.51cto.com/art/201104/253227.htm 下面我们来看看Spring中的Bean的4中依赖检查模式:simple,object,all,none ...
- spring 依赖注入总结
一.问题引入 官方为什么推荐构造器注入? 构造器注入和属性注入的区别是啥? 你知道有几种注入方式吗? 二 注入方式 spring的注入方式就两种 配置注入,注解注入(自动装配) 而这两种方式都实现了 ...
- Spring依赖注入–字段vs设置器vs构造函数注入
欢迎使用Spring Dependency Injection –字段,设置器,构造函数注入教程. 了解场注入 , 二传手注入和构造函数注入之间的区别. 借助代码示例,我们将看到使用每个示例的好处以及 ...
- Java程序员必须掌握的Spring依赖管理原理
Spring依赖注入 依赖注入(Dependency Injection)的意思就是对象通过构造器函数参数,工厂方法的参数,或者成员属性,定义了对象的依赖对象:容器在创建该对象时会负责注入这些依赖.这 ...
- Spring依赖处理过程源码分析
AbstractAutowireCapableBeanFactory#doCreateBean创建Bean AbstractAutowireCapableBeanFactory#populateBea ...
- Spring依赖注入与自动装配
Spring依赖注入与自动装配 首先推荐狂神说的Spring讲义 1.Beans.xml作用 简而言之,我们通过在beans.xml中进行配置,将各种类交给spring来管理. 2.依赖注入 推荐狂神 ...
- arg是什么函数_java后端开发三年!你还不了解Spring 依赖注入,凭什么给你涨薪...
前言 前两天和一个同学吃饭的时候同学跟我说了一件事,说他公司有个做了两年的人向他提出要涨薪资,他就顺口问了一个问题关于spring依赖注入的,那个要求涨薪的同学居然被问懵了...事后回家想了想这一块确 ...
最新文章
- sqlerror.java.1055,at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
- Python3.5在Windows7环境下Scrapy库的安装
- jwt判断token是否过期_前端也得搞懂 JWT 这个知识点
- DES的原理及python实现
- 2018年度全球收入52强App发行商榜单公布:腾讯连续三年居首
- Java学习之FileInputStream与FileReader的区别
- Django项目:CRM(客户关系管理系统)--83--73PerfectCRM实现CRM模板统一
- CSS大美集(关于细节)
- CDN的基本原理和基础架构
- HMM中的前向法(转)
- 酷比魔方iplay20_799元买国产“山寨板”是否值得?酷比魔方iPlay20 Pro评测
- 小白怎么入门网络安全?
- python系列教程158——iter函数
- 【Android】Android 封装 Http 请求工具
- 人工智能助力三维几何自动化建模
- 王菲微博“逗贫”语录暴光
- CN_计算机网络性能指标@信道利用率@信道吞吐率
- BG22蓝牙——第三弹 蓝牙的一些入门知识,整理了大佬们的文章和链接
- 云服务器有多少防御,高防服务器防御一般有多少?
- linux open firmware,Linux 5.3继续推进英特尔的Sound Open Firmware声音固件
热门文章
- OpenGL deferred shading延迟渲染的实例
- C++智能指针简单介绍
- c++TCP的三次握手和四次挥手
- 怎么用matlab处理数据,如何用Matlab处理.wfm格式的数据
- 第十天:估算活动持续时间,类比估算,参数估算,自下而上估算,三点估算解析表
- 09_EGIT插件的安装,Eclipse中克隆(clone),commit,push,pull操作演示
- 1高并发服务器:多进程服务器
- 微擎jsapi支付必须传openid怎么解决_面经腾讯微信支付面试记
- 怎么将数据进行正太转化_想要将电脑音频进行录制怎么操作
- mysql 动态游标_mysql动态游标与mysql存储过程游标(示例)