4个依赖检查支持的模式:
- none – 没有依赖检查,这是默认的模式。
- simple – 如果基本类型(int, long,double…)和集合类型(map, list..)的任何属性都没有设置,UnsatisfiedDependencyException将被抛出。
- objects – 如果对象类型的任何属性都没有设置,UnsatisfiedDependencyException将被抛出。
- all – 如果任何类型的任何属性都没有被设置,UnsatisfiedDependencyException将被抛出。
注:默认模式是 none
none:
<bean id="obj" class="com.xuzhiwen.spring9.Object1" dependency-check="none"> <property name="name" value="tom" /> </bean>
simple:
<bean id="obj" class="com.xuzhiwen.spring9.Object1" dependency-check="simple"> <property name="name" value="tom" /> </bean>
objects:
<bean id="obj" class="com.xuzhiwen.spring9.Object1" dependency-check="objects"> <property name="name" value="tom" /> </bean>
all:
<bean id="obj" class="com.xuzhiwen.spring9.Object1" dependency-check="all"> <property name="name" value="tom" /> </bean>
全局默认的依赖检查:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd" default-dependency-check="all"> </beans>
时间: 2024-10-15 23:31:22