Spring_04_XML配置

时间:2021-05-24 03:07:02   收藏:0   阅读:0

XML配置

  * beans.xml 配置class
    
      <!--
          使用Spring来创建对象,在Spring中这些都称为Bean

          Bean=对象
          Hello hello = new Hello();
          id=变量名
          class=new的对象
          property相当于对象的属性,给属性设置值

      -->


    <bean id="userImpl" class="com.shi.dao.UserDaoImpl"/>

    <bean id="mysqlImpl" class="com.shi.dao.UserDaoMysqlImpl"/>

    <bean id="oracleImpl" class="com.shi.dao.UserDaoOracleImpl"/>

    <bean id="userServiceImpl" class="com.shi.service.UserServiceImpl">  
      <property name="userDao" ref="oracleImpl"/>  //需要使用上面bean中的哪种实现就是这里填写哪个实现,通过service类的中属性的set方法进行依赖注入。
    </bean>
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!