Spring 基础
依赖检查属性
在bean的dependency-check属性中指定依赖检查模式就ok.依赖检查模式有none, simple, object 和 all.
注意的是依赖检查只是检查属性是否通过设值方法注入。
@Required和自定义注解检查属性
需要先在Bean配置文件中添加<context:annotation-config>
@Required注解适用于bean属性的setter方法并且它指示,受影响的bean属性必须在配置时被填充在XML配置文件中,否则容器将抛出BeanInitializationException例外。
自定义:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface AA{}
在使用自定义的注解的时候,需要在 RequiredAnnotationBeanPostProcessor的requiredAnnotationType 属性中指定。
<bean class="Org.springframework.beans.factory.annonotation.RequiredAnnotationBeanPostProcessor">
<property name="requiredAnnotationType">
<value>com.***.AA</value>
</property>
</bean>
自动装配
- 在bean属性中指定autowire类型
- 使用@Autowired和@Resource装配特定属性—-需要先在Bean配置文件中添加
<context:annotation-config>