spring AutowireCapableBeanFactory 自动注入

文档:http://docs.spring.io/spring/docs/3.0.x/javadoc-api/org/springframework/beans/factory/config/AutowireCapableBeanFactory.html

public interface AutowireCapableBeanFactoryextends BeanFactory

Extension of the BeanFactory interface to be implemented by bean factories that are capable of autowiring, provided that they want to expose this functionality for existing bean instances.

This subinterface of BeanFactory is not meant to be used in normal application code: stick to BeanFactory or ListableBeanFactory for typical use cases.

Integration code for other frameworks can leverage this interface to wire and populate existing bean instances that Spring does not control the lifecycle of. This is particularly useful for WebWork Actions and Tapestry Page objects, for example.

Note that this interface is not implemented by ApplicationContext facades, as it is hardly ever used by application code. That said, it is available from an application context too, accessible through ApplicationContext‘s ApplicationContext.getAutowireCapableBeanFactory() method.

You may also implement the BeanFactoryAware interface, which exposes the internal BeanFactory even when running in an ApplicationContext, to get access to an AutowireCapableBeanFactory: simply cast the passed-in BeanFactory to AutowireCapableBeanFactory.

AutowireCapableBeanFactory这个接口一般在applicationContext的内部是较少使用的,它的功能主要是为了装配applicationContext管理之外的Bean。

参考:Spring中AutowireCapableBeanFactory的使用

时间: 2024-08-25 22:01:24

spring AutowireCapableBeanFactory 自动注入的相关文章

java的反射原理与Spring的自动注入(转载)

Java反射原理与Spring的自动注入 反射的定义 java的反射机制就是在运行状态中, 对于任意一个类都能够知道这个类的所有属性和方法; 对于任意一个对象,都能够调用它的任意一个方法和属性. 这种动态获取的信息以及动态调用对象的方法的功能称为java语言的反射机制. Sping的自动注入原理 一个Bean的类: public class User{ private String username; private String mobile; public String getUsernam

Spring注解自动注入Bean

我们知道采用Spring注解时,配置如下: [html] view plaincopy <context:annotation-config /> <context:component-scan base-package="cn.itkt"></context:component-scan> 这样的话,在com包及其所有子包下的所有类如果含有@Component.@Controller.@Service.@Repository等注解的话都会自动纳入到

SSM-Spring-06:Spring的自动注入autowire的byName和byType

------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- di的注入上次讲了一些,这次主要阐述域属性的自动注入 先讲byType方式 看名字就知道是根据类型进行自动注入 案例: 实体类:(俩个,一个学生类,一个汽车类) package cn.dawn.day06autowire; /** * Created by Dawn on 2018/3/5. */ //student类 public class Student { private String name;

Spring中Bean的作用域、Spring的自动注入、在spring配置文件中引入属性文件

1. Bean的作用域 Bean的作用域默认为单例模式. 2. 自动注入 3. 在spring配置文件中引入属性文件 Bean的作用域默认为单例模式. 原文地址:https://www.cnblogs.com/mcl2238973568/p/11478426.html

Spring Boot自动注入原理

启用自动注入 使用注解@EnableAutoConfiguration开启自动注入功能. @EnableAutoConfiguration @AutoConfigurationPackage @Import(AutoConfigurationImportSelector.class) public @interface EnableAutoConfiguration { // ignore... } @AutoConfigurationPackage @Import(AutoConfigurat

spring 需要自动注入的类 可以申明为static 吗?

 @Autowired   private UserInfoService service;   private static UserInfoService service;

Spring框架使用ByName自动注入同名问题剖析

问题描述 ??我们在使用spring框架进行项目开发的时候,为了配置Bean的方便经常会使用到Spring当中的Autosire机制,Autowire根据注入规则的不同又可以分为==ByName==和==ByType==这两种机制(两者的用法和区别可以参考[email protected]官方文档).但大家在使用Autowire当中==ByName==机制的时候有没有思考过这样一个问题,当我们配置了两个name属性相同的Bean,Spring在自动注入的时候会采取怎样处理方式?会覆盖?还是抛出异

spring自动注入是单例还是多例?单例如何注入多例?

单例多例需要搞明白这些问题:      1. 什么是单例多例:      2. 如何产生单例多例:      3. 为什么要用单例多例      4. 什么时候用单例,什么时候用多例:   1. 什么是单例.多例: 所谓单例就是所有的请求都用一个对象来处理,比如我们常用的service和dao层的对象通常都是单例的,而多例则指每个请求用一个新的对象来处理,比如action; 单例模式和多例模式说明: 1. 单例模式和多例模式属于对象模式. 2. 单例模式的对象在整个系统中只有一份,多例模式可以有

Spring容器是如何实现 Bean 自动注入(xml)

入口web.xml web.xml 配置文件 <!-- Spring Config --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</par