IOC容器命名
With component scanning in the classpath, Spring generates bean names for unnamed components, following the rules described earlier: essentially, taking the simple class name and turning its initial character to lower-case. However, in the (unusual) special case when there is more than one character and both the first and second characters are upper case, the original casing gets preserved. These are the same rules as defined by java.beans.Introspector.decapitalize (which Spring uses here).
通过在类路径中进行组件扫描,Spring会按照前面描述的规则为未命名的组件生成Bean名称:从本质上讲,采用简单的类名称并将其初始字符转换为小写。但是,在(不寻常的)特殊情况下,如果有多个字符并且第一个和第二个字符均为大写字母,则会保留原始大小写。这些规则与java.beans.Introspector.decapitalize(由Spring在此处使用)定义的规则相同。
spring 扫描 生成bean 名称规则:
- 类名称 第一个字符大写 ,第二个字符小写 ,生成的bean name 为类名第一个字符小写后的字符串。
java 类 UserDao 扫描 bean name 值为 userDao
@repository
public class UserDao{
}
// appContext.getBean("userDao"); 获取UserDao实体类
- 类名 第一个第二个字符大写,生成的bean名不变 。
java 类 IUserDao 扫描 生成的bean name 值为: IUserDao
@repository
public class IUserDao{
}
// appContext.getBean("IUserDao"); 获取IUserDao实体类
// appContext.containsBean("iUserDao") 返回false
// appContext.containsBean("IUserDao") 返回true