除了Spring 学习记录5 BeanFactory 里写的几个接口外,BeanFactory的实现类还实现了一些其他接口,这篇文章主要介绍这些接口和实现类.

 

结构

Spring 学习记录6 BeanFactory(2)

DefaultListableBeanFactory和它的父类们除了实现了BF的各种接口以外还实现了AliasRegistry和BeanDefinitionRegistry接口.而且不同等级的父类和BF的相关接口都有交集..

 

AliasRegistry

这个接口根据说明来看意思是提供别名注册的服务.虽然没有实际使用过别名,不过1个bean确实可以有N个别名.

 1 /*
 2  * Copyright 2002-2008 the original author or authors.
 3  *
 4  * Licensed under the Apache License, Version 2.0 (the "License");
 5  * you may not use this file except in compliance with the License.
 6  * You may obtain a copy of the License at
 7  *
 8  *      http://www.apache.org/licenses/LICENSE-2.0
 9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package org.springframework.core;
18 
19 /**
20  * Common interface for managing aliases. Serves as super-interface for
21  * {@link org.springframework.beans.factory.support.BeanDefinitionRegistry}.
22  *
23  * @author Juergen Hoeller
24  * @since 2.5.2
25  */
26 public interface AliasRegistry {
27 
28     /**
29      * Given a name, register an alias for it.
30      * @param name the canonical name
31      * @param alias the alias to be registered
32      * @throws IllegalStateException if the alias is already in use
33      * and may not be overridden
34      */
35     void registerAlias(String name, String alias);
36 
37     /**
38      * Remove the specified alias from this registry.
39      * @param alias the alias to remove
40      * @throws IllegalStateException if no such alias was found
41      */
42     void removeAlias(String alias);
43 
44     /**
45      * Determine whether this given name is defines as an alias
46      * (as opposed to the name of an actually registered component).
47      * @param beanName the bean name to check
48      * @return whether the given name is an alias
49      */
50     boolean isAlias(String beanName);
51 
52     /**
53      * Return the aliases for the given name, if defined.
54      * @param name the name to check for aliases
55      * @return the aliases, or an empty array if none
56      */
57     String[] getAliases(String name);
58 
59 }
View Code

相关文章: