java框架:Spring关键配置(applicationContent.xml)

本文介绍了Spring框架的核心配置文件applicationContent.xml的作用及配置方法。详细解释了如何通过此文件定义bean及其依赖关系,使得Spring能够在运行时正确装配这些bean。

Spring 关键配置体现在其核心配置文件中,一般Spring默认的核心配置就是applicationContent.xml.这里可以配置各个bean彼此间的依赖关系。同时 ,Spring可以通过这个文件知道各个bean基本信息,并在运行过程中装配起来。

eg:applicationContent.xml 通过关键字c即可获取Category对象,该对象获取的时候,即被注入了字符串"category 1“到name属性中

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
   http://www.springframework.org/schema/beans 
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/aop 
   http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
   http://www.springframework.org/schema/tx 
   http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
   http://www.springframework.org/schema/context      
   http://www.springframework.org/schema/context/spring-context-3.0.xsd">
 
    <bean name="c" class="com.how2java.pojo.Category">
        <property name="name" value="category 1" />
    </bean>
     <bean id="chinese" class ="com.people.chinese"></bean></beans>

  <beans>可以包含多个<bean > ,<bean>定义一个bean如何被装配到Spring容器中(任何一个java对象均可作为bean进行定义)。id属性为指定bean唯一标识符,在整个Spring容器中必须是唯一的。class为指定bean的具体实现类。

Bean之间的依赖配置

    实际上,不同bean之间往往有一定的依赖关系。这个时候就需要进行依赖配置了,具体可参考我的上一篇文章

java框架:Spring 及其依赖注入方式   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值