Spring Framework系列--ApplicationContext配置标签详解(一)bean的基础标签配置

网上一直没有找到很好的博客说明,想着还是自己整合一份材料算了。。。

本文的结构是以一个个小样例的形式给出,通过小样例来介绍一个个标签的作用。

样例1:

样例1展示了一个最简单的bean对象配置文件的写法。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="accountDao"
          class="org.springframework.samples.jpetstore.dao.jpa.JpaAccountDao">
        <!-- additional collaborators and configuration for this bean go here -->
    </bean>

    <bean id="itemDao" class="org.springframework.samples.jpetstore.dao.jpa.JpaItemDao">
        <!-- additional collaborators and configuration for this bean go here -->
    </bean>

    <!-- more bean definitions for data access objects go here -->

</beans>
标签名 所属上级标签 说明
<beans>
放置所有bean对象配置信息的标签
<bean> <beans> 用来声明一个bean对象的标签,内置属性用来描述该对象配置的一些信息
<bean id> <bean> <bean>中的属性,用一个字符串来标识这个bean对象,其他bean对象可以用这个字符串来引用这个bean
<bean class> <bean>             <bean>中的属性,用来说明这个bean是用那个java类创建的,需要使用java类的全限定名。

样例2:

样例2中的bean引用是基于样例1中的两个bean的定义,展示了如果bean中有需要依赖的对象,应该如何声明。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值