IOC容器命名

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 名称规则:

  1. 类名称 第一个字符大写 ,第二个字符小写 ,生成的bean name 为类名第一个字符小写后的字符串。

java 类 UserDao 扫描 bean name 值为 userDao

@repository
public  class   UserDao{
  
}
// appContext.getBean("userDao");  获取UserDao实体类
  1. 类名 第一个第二个字符大写,生成的bean名不变 。
    java 类 IUserDao 扫描 生成的bean name 值为: IUserDao
@repository
public  class   IUserDao{
  
}
// appContext.getBean("IUserDao");  获取IUserDao实体类 
// appContext.containsBean("iUserDao")  返回false
// appContext.containsBean("IUserDao")  返回true
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值