spring中的依赖检查

it2024-09-26  17

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>

 

转载于:https://www.cnblogs.com/beibidewomen/p/7411550.html

最新回复(0)