zoukankan      html  css  js  c++  java
  • Spring---bean的命名

    每个Bean可以有一个或多个 id,我们把第一个 id 称为“标识符”,其余id叫做“别名”,这些id在 IoC 容器中必须唯一。

    Bean  id 的命名约定:

    1. 遵循XML命名规范
    2. 由字母,数字,下划线组成
    3. 驼峰式,首个单词字母大写

    Bean  id 的命名方式:

    • 配置全限定类名,唯一
    • 指定id,唯一
    • 指定name,唯一
    • 指定id和name,唯一
    • 指定多个name,唯一
    • 指定别名,唯一
    <!-- 配置全限定类名 -->
    <bean class="com.jike.spring.chapter04.definition.HelloWorldImpl" />
    <!-- 指定id -->
    <bean id="helloWorld" class="com.jike.spring.chapter04.definition.HelloWorldImpl" />
    main中
    beanFactory.getBean("helloWorld" , helloWorld.class);
    <!-- 指定name -->
    <bean name="helloWorldByName" class="com.jike.spring.chapter04.definition.HelloWorldImpl" />
    main中
    beanFactory.getBean("helloWorld" , helloWorld.class);
    <!-- 指定id和name -->这样既可以通过id,也可以通过name获取到类的实例
    <bean id="helloWorldById" name="helloWorldByName01" class="com.jike.spring.chapter04.definition.HelloWorldImpl" />
    <!-- 指定多个name -->
    <bean name="bean1;alias11;alias12;alias13" class="com.jike.spring.chapter04.definition.HelloWorldImpl" />
    <bean id="bean2" name="alias21,alias22,alias23" class="com.jike.spring.chapter04.definition.HelloWorldImpl" />
    <!-- 指定别名 -->
    <bean name="bean3" class="com.jike.spring.chapter04.definition.HelloWorldImpl" />
    <alias alias="alias31" name="bean3" />
    <alias alias="alias32" name="bean3" />
  • 相关阅读:
    Pascal's Triangle 2(leetcode java)
    118. Pascal's Triangle (java)
    Bulb Switcher (leetcode java)
    Lowest Common Ancestor of a Binary Search Tree(Java 递归与非递归)
    Remove Duplicate Letters(Java 递归与非递归)
    读大道至简有感
    自学Java第一周的总结
    jmeter----jpgc----ultimate thread group
    jmeter----jpgc----stepping thread group
    jmter--jpgc模块
  • 原文地址:https://www.cnblogs.com/xiaobaizhiqian/p/7821112.html
Copyright © 2011-2022 走看看