依赖检查

依赖检查

Spring中的Bean中有种依赖检查模式:nonesimpleobjectall

1、  none:不进行依赖检查

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

  <bean id="emp" class="cn.csdn.domain.Emp" scope="singleton"/>

  <bean id="empServiceImpl" class="cn.csdn.service.EmpServiceImpl" scope="singleton" dependency-check="none">

     <property name="name">

        <value>kouxiaolin</value>

     </property>

     <property name="email">

       <value>kouxiaolin@qq.com</value>

     </property>

     <property name="list">

       <list>

        <ref bean="emp"/>

       </list>

     </property>

   </bean>

</beans>

 2、

  simple

 

simple

 

对于原始类型及集合(除协作者外的一切东西)执行依赖检查

 

 

3、  object:对依赖的对象进行检查(仅对协作者执行依赖检查)

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

  <bean id="emp" class="cn.csdn.domain.Emp" scope="singleton"/>

  <bean id="empServiceImpl" class="cn.csdn.service.EmpServiceImpl" scope="singleton" dependency-check="object">

     <property name="name">

        <value>kouxiaolin</value>

     </property>

     <property name="email">

       <value>kouxiaolin@qq.com</value>

     </property>

     <property name="list">

       <list>

        <ref bean="emp"/>

       </list>

     </property>

   </bean>

</beans>

  

 

 

4、  all:对全部属性进行检查

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

  <bean id="emp" class="cn.csdn.domain.Emp" scope="singleton"/>

  <bean id="empServiceImpl" class="cn.csdn.service.EmpServiceImpl" scope="singleton" dependency-check="all">

     <property name="name">

        <value>kouxiaolin</value>

     </property>

     <property name="email">

       <value>kouxiaolin@qq.com</value>

     </property>

     <property name="list">

       <list>

        <ref bean="emp"/>//引用上一个bean用<ref bean=”emp”/>

       </list>

     </property>

   </bean>

</beans>

 注:

bean 类中如果没有属性只有 set 方法会不会出错啊?

答案是没有错,因为依赖检查主要是检查bean中的setter方法的属性是否在配置文件中设置property属性

Bean

 

备注:

依赖检查主要是检查bean中的setter方法的属性是否在配置文件中设置property属性如果没有设置就会出现bug

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'empServiceImpl' defined in file [D:\Workspaces\MyEclipse 8.6\20110419_04\bin\check.xml]: Unsatisfied dependency expressed through bean property 'email': Set this property value or disable dependency checking for this bean.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值