Spring Bean 定义


当前第2页 返回上一页

你已经看到了如何把基于 XML 的配置元数据提供给容器,但是让我们看看另一个基于 XML 配置文件的例子,这个配置文件中有不同的 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-3.0.xsd">

   <!-- A simple bean definition -->
   <bean id="..." class="...">
       <!-- collaborators and configuration for this bean go here -->
   </bean>

   <!-- A bean definition with lazy init set on -->
   <bean id="..." class="..." lazy-init="true">
       <!-- collaborators and configuration for this bean go here -->
   </bean>

   <!-- A bean definition with initialization method -->
   <bean id="..." class="..." init-method="...">
       <!-- collaborators and configuration for this bean go here -->
   </bean>

   <!-- A bean definition with destruction method -->
   <bean id="..." class="..." destroy-method="...">
       <!-- collaborators and configuration for this bean go here -->
   </bean>

   <!-- more bean definitions go here -->

</beans>

在上述示例中:

①xmlns="http://www.springframework.org/schema/beans",默认命名空间:它没有空间名,用于Spring Bean的定义;

②xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance",xsi命名空间:这个命名空间用于为每个文档中命名空间指定相应的Schema样式文件,是标准组织定义的标准命名空间。

你可以查看 Spring Hello World 实例 来详细理解如何定义,配置和创建 Spring Beans。

关于基于注解的配置将在一个单独的章节中进行讨论。刻意把它保留在一个单独的章节,是因为我想让你在开始使用注解和 Spring 依赖注入编程之前,能掌握一些其他重要的 Spring 概念。



标签:Spring IoC

返回前面的内容

相关阅读 >>

spring mvc hello world 例子

spring 声明式事务管理

spring 中 sql 的存储过程

spring bean 后置处理器

spring 基于 java 的配置

spring 页面重定向例子

spring 自动装配 bytype

spring 中的事件处理

spring 基于设值函数的依赖注入

spring bean 作用域

更多相关阅读请进入《Spring IoC》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...