目录搜索
前言简介概览使用场景Spring 2.0和 2.5的新特性简介控制反转(IoC)容器新的bean作用域更简单的XML配置可扩展的XML编写Annotation(注解)驱动配置在classpath中自动搜索组件面向切面编程(AOP)更加简单的AOP XML配置对@AspectJ 切面的支持对bean命名pointcut( bean name pointcut element)的支持对AspectJ装载时织入(AspectJ load-time weaving)的支持中间层在XML里更为简单的声明性事务配置对Websphere 事务管理的完整支持JPA异步的JMSJDBCWeb层Spring MVC合理的默认值Portlet 框架基于Annotation的控制器Spring MVC的表单标签库对Tiles 2 支持对JSF 1.2支持JAX-WS支持其他动态语言支持增强的测试支持JMX 支持将Spring 应用程序上下文部署为JCA adapter计划任务对Java 5 (Tiger) 支持移植到Spring 2.5改变支持的JDK版本Spring 2.5的Jar打包XML配置Deprecated(淘汰)的类和方法Apache OJBiBATISHibernateJDOUrlFilenameViewController更新的样例应用改进的文档核心技术IoC(控制反转)容器简介基本原理 - 容器和bean容器配置元数据实例化容器XML配置元数据的结构多种beanbean的命名bean的别名实例化bean用构造器来实例化使用静态工厂方法实例化使用实例工厂方法实例化使用容器依赖注入依赖构造器注入构造器参数解析构造器参数类型匹配构造参数索引Setter注入一些例子依赖配置详解直接变量(基本类型、Strings类型等。)idref元素引用其它的bean(协作者)内部bean集合集合的合并强类型集合(仅适用于Java5+)NullsXML配置文件的简写及其他XML-based configuration metadata shortcuts使用p名称空间配置属性组合属性名称使用depends-on延迟初始化bean自动装配(autowire)协作者将bean排除在自动装配之外依赖检查方法注入Lookup方法注入自定义方法的替代方案Bean的作用域Singleton作用域Prototype作用域Singleton beans和prototype-bean的依赖其他作用域初始化web配置Request作用域Session作用域global session作用域作用域bean与依赖选择创建代理的类型自定义作用域创建自定义作用域使用自定义作用域定制bean特性生命周期回调初始化回调析构回调缺省的初始化和析构方法组合生命周期机制在非web应用中优雅地关闭Spring IoC容器了解自己BeanFactoryAwareBeanNameAwarebean定义的继承容器扩展点用BeanPostProcessor定制bean使用BeanPostProcessor的Hello World示例RequiredAnnotationBeanPostProcessor示例用BeanFactoryPostProcessor定制配置元数据PropertyPlaceholderConfigurer示例PropertyOverrideConfigurer示例使用FactoryBean定制实例化逻辑The ApplicationContextBeanFactory 还是 ApplicationContext?利用MessageSource实现国际化事件底层资源的访问ApplicationContext在WEB应用中的实例化粘合代码和可怕的singleton以J2EE RAR文件的形式部署Spring ApplicationContext基于注解(Annotation-based)的配置@Autowired基于注解的自动连接微调CustomAutowireConfigurer@Resource@PostConstruct 与 @PreDestroy对受管组件的Classpath扫描@Component和更多典型化注解自动检测组件使用过滤器自定义扫描自动检测组件的命名为自动检测的组件提供一个作用域用注解提供限定符元数据注册一个LoadTimeWeaver资源简介Resource接口内置 Resource 实现UrlResourceClassPathResourceFileSystemResourceServletContextResourceInputStreamResourceByteArrayResourceResourceLoader接口ResourceLoaderAware 接口把Resource作为属性来配置Application context 和Resource 路径构造application context创建 ClassPathXmlApplicationContext 实例 - 简介Application context构造器中资源路径的通配符Ant风格的pattern潜在的可移植性classpath*: 前缀其他关于通配符的说明FileSystemResource 说明校验,数据绑定,BeanWrapper,与属性编辑器简介使用Spring的Validator接口进行校验从错误代码到错误信息Bean处理和BeanWrapper设置和获取属性值以及嵌套属性内建的PropertyEditor实现注册用户自定义的PropertyEditor使用PropertyEditorRegistrars使用Spring进行面向切面编程(AOP)简介AOP概念Spring AOP的功能和目标AOP代理@AspectJ支持启用@AspectJ支持声明一个切面声明一个切入点(pointcut)切入点指示符(PCD)的支持组合切入点表达式共享通用切入点定义示例声明通知前置通知后置通知(After returning advice)异常通知(After throwing advice)最终通知(After (finally) advice)环绕通知通知参数(Advice parameters)访问当前的连接点传递参数给通知确定参数名处理参数通知顺序引入(Introduction)切面实例化模型例子基于Schema的AOP支持声明一个切面声明一个切入点声明通知前置通知后置通知异常通知最终通知环绕通知通知参数通知顺序引入切面实例化模型Advisor例子AOP声明风格的选择Spring AOP还是完全用AspectJ?Spring AOP中使用@AspectJ还是XML?混合切面类型代理机制理解AOP代理以编程方式创建@AspectJ代理在Spring应用中使用AspectJ在Spring中使用AspectJ进行domain object的依赖注入@Configurable对象的单元测试Working with multiple application contextsSpring中其他的AspectJ切面使用Spring IoC来配置AspectJ的切面在Spring应用中使用AspectJ加载时织入(LTW)第一个例子切面'META-INF/aop.xml'相关类库(JARS)Spring配置特定环境的配置通用Java应用TomcatWebLogic更多资源Spring AOP APIs简介Spring中的切入点API概念切入点运算AspectJ切入点表达式便利的切入点实现静态切入点正则表达式切入点属性驱动的切入点动态切入点控制流切入点切入点的超类自定义切入点Spring的通知API通知的生命周期Spring里的通知类型拦截环绕通知前置通知异常通知后置通知引入通知Spring里的Advisor API使用ProxyFactoryBean创建AOP代理基础JavaBean属性基于JDK和CGLIB的代理对接口进行代理对类进行代理使用“全局”通知器简化代理定义使用ProxyFactory通过编程创建AOP代理操作被通知对象使用“自动代理(autoproxy)”功能自动代理bean定义BeanNameAutoProxyCreatorDefaultAdvisorAutoProxyCreatorAbstractAdvisorAutoProxyCreator使用元数据驱动的自动代理使用TargetSource热交换目标源池化目标源原型目标源ThreadLocal目标源定义新的Advice类型更多资源测试简介单元测试Mock对象JNDIServlet APIPortlet API单元测试支持类通用工具类Spring MVC集成测试概览使用哪个支持框架通用目标上下文管理及缓存测试fixtures依赖注入事务管理集成测试支持类JDBC测试支持常用注解JUnit 3.8遗留支持上下文管理及缓存测试fixture依赖注入字段级别(Field Level)注入事务管理JUnit 3.8 遗留支持类Java 5+ 专有支持使用注解的事务相关测试JPA支持类Spring TestContext Framework主要的抽象上下文管理和缓存测试fixture的依赖注入事务管理TestContext支持类JUnit 3.8支持类JUnit 4.4支持类定制JUnit 4.4运行器TestNG支持类TestContext框架注解支持PetClinic示例更多资源中间层数据访问事务管理简介动机关键抽象使用资源同步的事务高层次方案低层次方案TransactionAwareDataSourceProxy声明式事务管理理解Spring的声明式事务管理实现第一个例子回滚为不同的bean配置不同的事务语义<tx:advice/> 有关的设置使用 @Transactional@Transactional 有关的设置事务传播requiredRequiresNewNested通知事务操作结合AspectJ使用 @Transactional编程式事务管理使用TransactionTemplate指定事务设置使用PlatformTransactionManager选择编程式事务管理还是声明式事务管理与特定应用服务器集成IBM WebSphereBEA WebLogicOracle OC4J常见问题的解决方法对一个特定的 DataSource 使用了错误的事务管理器更多的资源DAO支持简介一致的异常层次一致的DAO支持抽象类使用JDBC进行数据访问简介选择一种工作模式Spring JDBC包结构利用JDBC核心类控制JDBC的基本操作和错误处理JdbcTemplate类一些示例查询(SELECT)更新(INSERT/UPDATE/DELETE)其他操作JdbcTemplate 的最佳实践NamedParameterJdbcTemplate类SimpleJdbcTemplate类DataSource接口SQLExceptionTranslator接口执行SQL语句执行查询更新数据库获取自动生成的主键控制数据库连接DataSourceUtils类SmartDataSource接口AbstractDataSource类SingleConnectionDataSource类DriverManagerDataSource类TransactionAwareDataSourceProxy类DataSourceTransactionManager类NativeJdbcExtractorJDBC批量操作使用JdbcTemplate进行批量操作使用SimpleJdbcTemplate进行批量操作通过使用SimpleJdbc类简化JDBC操作使用SimpleJdbcInsert插入数据使用SimpleJdbcInsert来获取自动生成的主键指定SimpleJdbcInsert所使用的字段使用SqlParameterSource提供参数值使用SimpleJdbcCall调用存储过程声明SimpleJdbcCall使用的参数如何定义SqlParameters使用SimpleJdbcCall调用内置函数使用SimpleJdbcCall返回的ResultSet/REF Cursor用Java对象来表达JDBC操作SqlQuery类MappingSqlQuery类SqlUpdate类StoredProcedure类SqlFunction类参数和数据处理的基本原则为参数设置SQL类型信息处理BLOB 和 CLOB对象在IN语句中传入一组参数值处理复杂类型的存储过程调用使用ORM工具进行数据访问简介Hibernate资源管理在Spring容器中创建 SessionFactoryThe HibernateTemplate不使用回调的基于Spring的DAO实现基于Hibernate3的原生API实现DAO编程式的事务划分声明式的事务划分事务管理策略容器资源 vs 本地资源在应用服务器中使用Hibernate的注意事项JDO建立PersistenceManagerFactoryJdoTemplate和JdoDaoSupport基于原生的JDO API实现DAO事务管理JdoDialectOracle TopLinkSessionFactory 抽象层TopLinkTemplate and TopLinkDaoSupport基于原生的TopLink API的DAO实现事务管理iBATIS SQL Maps创建SqlMapClient使用 SqlMapClientTemplate 和 SqlMapClientDaoSupport基于原生的iBATIS API的DAO实现JPA在Spring环境中建立JPALocalEntityManagerFactoryBean从JNDI中获取 EntityManagerFactoryLocalContainerEntityManagerFactoryBeanTomcat(5.0以上)加载时的织入配置使用VM代理的全局加载时织入上下文范围内的加载时织入配置处理多持久化单元JpaTemplate 和 JpaDaoSupport基于原生的JPA实现DAO异常转化事务管理JpaDialectThe WebWeb MVC framework Web框架概述与其他MVC实现框架的集成Spring Web MVC框架的特点DispatcherServlet控制器AbstractController 和 WebContentGenerator其它的简单控制器MultiActionController命令控制器处理器映射(handler mapping)BeanNameUrlHandlerMappingSimpleUrlHandlerMapping拦截器(HandlerInterceptor)视图与视图解析视图解析器(ViewResolver)视图解析链重定向(Rediret)到另一个视图RedirectViewredirect:前缀forward:前缀本地化解析器AcceptHeaderLocaleResolverCookieLocaleResolverSessionLocaleResolverLocaleChangeInterceptor使用主题简介如何定义主题主题解析器Spring对分段文件上传(multipart file upload)的支持介绍使用MultipartResolver在表单中处理分段文件上传使用Spring的表单标签库配置form标签input标签checkbox标签checkboxes标签radiobutton标签radiobuttons标签password标签select标签option标签options标签textarea标签hidden标签errors标签处理异常惯例优先原则(convention over configuration)对控制器的支持:ControllerClassNameHandlerMapping对模型的支持:ModelMap(ModelAndView)对视图的支持:RequestToViewNameTranslator基于注解的控制器配置建立dispatcher实现注解支持使用@Controller定义一个控制器使用@RequestMapping映射请求使用@RequestParam绑定请求参数到方法参数使用@ModelAttribute提供一个从模型到数据的链接使用@SessionAttributes指定存储在会话中的属性自定义WebDataBinder初始化使用@InitBinder自定义数据绑定配置一个定制的WebBindingInitializer更多资源集成视图技术简介JSP和JSTL视图解析器'Plain-old' JSPs versus JSTL 'Plain-old' JSP与JSTL帮助简化开发的额外的标签Tiles需要的资源如何集成TilesUrlBasedViewResolver类ResourceBundleViewResolver类SimpleSpringPreparerFactory 和 SpringBeanPreparerFactoryVelocity和FreeMarker需要的资源Context 配置创建模板高级配置velocity.propertiesFreeMarker绑定支持和表单处理用于绑定的宏简单绑定表单输入生成宏输入域选择输入域重载HTML转码行为并使你的标签符合XHTMLXSLT写在段首Bean 定义标准MVC控制器代码把模型数据转化为XML定义视图属性文档转换小结文档视图(PDF/Excel)简介配置和安装文档视图定义Controller 代码Excel视图子类PDF视图子类JasperReports依赖的资源配置配置ViewResolver配置View关于报表文件使用 JasperReportsMultiFormatView构造ModelAndView使用子报表配置子报表文件配置子报表数据源配置Exporter的参数集成其它Web框架简介通用配置JavaServer FacesDelegatingVariableResolverFacesContextUtilsStrutsContextLoaderPluginDelegatingRequestProcessorDelegatingActionProxyActionSupport ClassesTapestry注入 Spring 托管的 beans将 Spring Beans 注入到 Tapestry 页面中组件定义文件添加抽象访问方法将 Spring Beans 注入到 Tapestry 页面中 - Tapestry 4.0+ 风格WebWork更多资源Portlet MVC框架介绍控制器 - MVC中的C视图 - MVC中的VWeb作用范围的BeanDispatcherPortletViewRendererServlet控制器AbstractController 和 PortletContentGenerator其它简单的控制器Command控制器PortletWrappingController处理器映射PortletModeHandlerMappingParameterHandlerMappingPortletModeParameterHandlerMapping增加 HandlerInterceptorsHandlerInterceptorAdapterParameterMappingInterceptor视图和它们的解析Multipart文件上传支持使用 PortletMultipartResolver处理表单里的文件上传异常处理Portlet应用的部署整合使用Spring进行远程访问与Web服务简介使用RMI暴露服务使用RmiServiceExporter暴露服务在客户端链接服务使用Hessian或者Burlap通过HTTP远程调用服务为Hessian和co.配置DispatcherServlet使用HessianServiceExporter暴露你的bean在客户端连接服务使用Burlap对通过Hessian或Burlap暴露的服务使用HTTP Basic认证使用HTTP调用器暴露服务Exposing the service object在客户端连接服务Web Services使用JAX-RPC暴露基于servlet的web服务使用JAX-RPC访问web服务注册JAX-RPC Bean映射注册自己的JAX-RPC 处理器使用JAX-WS暴露基于servlet的web服务使用JAX-WS暴露单独web服务使用Spring支持的JAX-WS RI来暴露服务使用JAX-WS访问web服务使用XFire来暴露Web服务JMS服务端配置客户端配置对远程接口不提供自动探测实现在选择这些技术时的一些考虑Enterprise Java Beans (EJB) 集成简介访问EJB概念访问本地的无状态Session Bean(SLSB)访问远程SLSBAccessing EJB 2.x SLSBs versus EJB 3 SLSBs使用Spring提供的辅助类实现EJB组件EJB 2.x base classesEJB 3 注入拦截JMS (Java Message Service)简介使用Spring JMSJmsTemplate连接工厂目的地管理消息侦听容器SimpleMessageListenerContainerDefaultMessageListenerContainerServerSessionMessageListenerContainer事务管理发送消息使用消息转换器SessionCallback 和 ProducerCallback接收消息同步接收异步接收 - 消息驱动的POJOSessionAwareMessageListener接口MessageListenerAdapter事务中的消息处理JCA消息端点的支持JMS命名空间支持JMX介绍将Bean暴露为JMX创建MBeanServer重用原有的MBeanServer延迟初始化的MBeanMBean的自动注册控制注册行为控制Bean的管理接口MBeanInfoAssembler接口使用源码级元数据使用JDK 5.0的注解源代码级的元数据类型AutodetectCapableMBeanInfoAssembler接口用Java接口定义管理接口使用MethodNameBasedMBeanInfoAssembler控制Bean的ObjectName从Properties读取Properties使用MetadataNamingStrategy<context:mbean-export/>元素JSR-160连接器服务器端连接器客户端连接器基于Burlap/Hessian/SOAP的JMX通过代理访问MBean通知为通知注册监听器发布通知更多资源JCA CCI简介配置CCI连接器配置在Spring中配置ConnectionFactory配置CCI连接使用一个 CCI 单连接使用Spring的 CCI访问支持记录转换CciTemplate类DAO支持自动输出记录生成总结直接使用一个CCI Connection接口和Interaction接口CciTemplate 使用示例建模CCI访问为操作对象MappingRecordOperationMappingCommAreaOperation自动生成输出记录总结MappingRecordOperation 使用示例MappingCommAreaOperation 使用示例事务Spring邮件抽象层简介使用Spring邮件抽象MailSender 和 SimpleMailMessage 的基本用法使用 JavaMailSender 和 MimeMessagePreparator使用MimeMessageHelper发送附件和嵌入式资源(inline resources)附件内嵌资源使用模板来创建邮件内容一个基于Velocity的示例Spring中的定时调度(Scheduling)和线程池(Thread Pooling)简介使用OpenSymphony Quartz 调度器使用JobDetailBean使用 MethodInvokingJobDetailFactoryBean使用triggers和SchedulerFactoryBean来包装任务使用JDK Timer支持类创建定制的timers使用 MethodInvokingTimerTaskFactoryBean类最后:使用TimerFactoryBean来设置任务SpringTaskExecutor抽象TaskExecutor接口TaskExecutor类型使用TaskExecutor动态语言支持介绍第一个示例定义动态语言支持的bean公共概念<lang:language/> 元素Refreshable bean内置动态语言源文件理解dynamic-language-backed bean上下文中的构造器注入JRuby beansGroovy beans通过回调定制Groovy对象BeanShell beans场景Spring MVC控制器的脚本化Validator的脚本化Bits and bobsAOP - 通知脚本化bean作用域更多的资源注解和源代码级的元数据支持简介Spring的元数据支持注解@RequiredSpring中的其它@AnnotationsJakarta Commons Attributes集成元数据和Spring AOP自动代理基本原理声明式事务管理示例程序演示案例介绍使用动态语言实现的Spring MVC控制器构建与部署使用SimpleJdbcTemplate和@Repository实现DAO域对象Data Access Object构建XML Schema-based configurationIntroductionXML Schema-based configurationReferencing the schemasThe util schema<util:constant/>Setting a bean property or constructor arg from a field value<util:property-path/>Using <util:property-path/> to set a bean property or constructor-argument<util:properties/><util:list/><util:map/><util:set/>The jee schema<jee:jndi-lookup/> (simple)<jee:jndi-lookup/> (with single JNDI environment setting)<jee:jndi-lookup/> (with multiple JNDI environment settings)<jee:jndi-lookup/> (complex)<jee:local-slsb/> (simple)<jee:local-slsb/> (complex)<jee:remote-slsb/>The lang schemaThe jms schemaThe tx (transaction) schemaThe aop schemaThe context schema<property-placeholder/><annotation-config/><component-scan/><load-time-weaver/><spring-configured/><mbean-export/>The tool schemaThe beans schemaSetting up your IDESetting up EclipseSetting up IntelliJ IDEAIntegration issuesXML parsing errors in the Resin v.3 application serverExtensible XML authoringIntroductionAuthoring the schemaCoding a NamespaceHandlerCoding a BeanDefinitionParserRegistering the handler and the schema'META-INF/spring.handlers''META-INF/spring.schemas'Using a custom extension in your Spring XML configurationMeatier examplesNesting custom tags within custom tagsCustom attributes on 'normal' elementsFurther Resourcesspring-beans-2.0.dtdspring.tldIntroductionThe bind tagThe escapeBody tagThe hasBindErrors tagThe htmlEscape tagThe message tagThe nestedPath tagThe theme tagThe transform tagspring-form.tldIntroductionThe checkbox tagThe checkboxes tagThe errors tagThe form tagThe hidden tagThe input tagThe label tagThe option tagThe options tagThe password tagThe radiobutton tagThe radiobuttons tagThe select tagThe textarea tagSpring 2.5开发手册中文化项目声明致谢参与人员项目历程
文字

A.2. XML Schema-based configuration

A.2.1. Referencing the schemas

To switch over from the DTD-style to the new XML Schema-style, you need to make the following change.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
    "http://www.springframework.org/dtd/spring-beans-2.0.dtd">

<beans>

<!-- <bean/> definitions here -->

</beans>

The equivalent file in the XML Schema-style would be...

<?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-2.5.xsd">

<!-- <bean/> definitions here -->

</beans>

注意

The 'xsi:schemaLocation' fragment is not actually required, but can be included to reference a local copy of a schema (which can be useful during development).

The above Spring XML configuration fragment is boilerplate that you can copy and paste (!) and then plug <bean/> definitions into like you have always done. However, the entire point of switching over is to take advantage of the new Spring 2.0 XML tags since they make configuration easier. The section entitled 第 A.2.2 节 “The util schema” demonstrates how you can start immediately by using some of the more common utility tags.

The rest of this chapter is devoted to showing examples of the new Spring XML Schema based configuration, with at least one example for every new tag. The format follows a before and after style, with a before snippet of XML showing the old (but still 100% legal and supported) style, followed immediately by an after example showing the equivalent in the new XML Schema-based style.

A.2.2. The util schema

First up is coverage of the util tags. As the name implies, the util tags deal with common, utility configuration issues, such as configuring collections, referencing constants, and suchlike.

To use the tags in the util schema, you need to have the following preamble at the top of your Spring XML configuration file; the emboldened text in the snippet below references the correct schema so that the tags in the util namespace are available to you.

<?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:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">

<!-- <bean/> definitions here -->

</beans>

A.2.2.1. <util:constant/>

Before...

<bean id="..." class="...">
  <property name="isolation">
    <bean id="java.sql.Connection.TRANSACTION_SERIALIZABLE"
    class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean" />
  </property>
</bean>

The above configuration uses a Spring FactoryBean implementation, the FieldRetrievingFactoryBean, to set the value of the 'isolation' property on a bean to the value of the 'java.sql.Connection.TRANSACTION_SERIALIZABLE' constant. This is all well and good, but it is a tad verbose and (unneccessarily) exposes Spring's internal plumbing to the end user.

The following XML Schema-based version is more concise and clearly expresses the developer's intent ('inject this constant value'), and it just reads better.

<bean id="..." class="...">
  <property name="isolation">
    <util:constant static-field="java.sql.Connection.TRANSACTION_SERIALIZABLE"/>
  </property>
</bean>
A.2.2.1.1. Setting a bean property or constructor arg from a field value

FieldRetrievingFactoryBean is a FactoryBean which retrieves a static or non-static field value. It is typically used for retrieving public static final constants, which may then be used to set a property value or constructor arg for another bean.

Find below an example which shows how a static field is exposed, by using the staticField property:

<bean id="myField"
        class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
  <property name="staticField" value="java.sql.Connection.TRANSACTION_SERIALIZABLE"/>
</bean>

There is also a convenience usage form where the static field is specified as the bean name:

<bean id="java.sql.Connection.TRANSACTION_SERIALIZABLE"
    class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean"/>

This does mean that there is no longer any choice in what the bean id is (so any other bean that refers to it will also have to use this longer name), but this form is very concise to define, and very convenient to use as an inner bean since the id doesn't have to be specified for the bean reference:

<bean id="..." class="...">
  <property name="isolation">
    <bean id="java.sql.Connection.TRANSACTION_SERIALIZABLE"
          class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean" />
  </property>
</bean>

It is also possible to access a non-static (instance) field of another bean, as described in the API documentation for the FieldRetrievingFactoryBean class.

Injecting enum values into beans as either property or constructor arguments is very easy to do in Spring, in that you don't actually have to do anything or know anything about the Spring internals (or even about classes such as the FieldRetrievingFactoryBean). Let's look at an example to see how easy injecting an enum value is; consider this JDK 5 enum:

package javax.persistence;
     
public enum PersistenceContextType {

    TRANSACTION,
    EXTENDED

}

Now consider a setter of type PersistenceContextType:

package example;

public class Client {

    private PersistenceContextType persistenceContextType;

    public void setPersistenceContextType(PersistenceContextType type) { 
        this.persistenceContextType = type;
    }
}

.. and the corresponding bean definition:

<bean class="example.Client">
    <property name="persistenceContextType" value="TRANSACTION" />
</bean>

This works for classic type-safe emulated enums (on JDK 1.4 and JDK 1.3) as well; Spring will automatically attempt to match the string property value to a constant on the enum class.

A.2.2.2. <util:property-path/>

Before...

<!-- target bean to be referenced by name -->
<bean id="testBean" class="org.springframework.beans.TestBean" scope="prototype">
  <property name="age" value="10"/>
  <property name="spouse">
    <bean class="org.springframework.beans.TestBean">
      <property name="age" value="11"/>
    </bean>
  </property>
</bean>

<!-- will result in 10, which is the value of property 'age' of bean 'testBean' -->
<bean id="testBean.age" class="org.springframework.beans.factory.config.PropertyPathFactoryBean"/>

The above configuration uses a Spring FactoryBean implementation, the PropertyPathFactoryBean, to create a bean (of type int) called 'testBean.age' that has a value equal to the 'age' property of the 'testBean' bean.

After...

<!-- target bean to be referenced by name -->
<bean id="testBean" class="org.springframework.beans.TestBean" scope="prototype">
  <property name="age" value="10"/>
  <property name="spouse">
    <bean class="org.springframework.beans.TestBean">
      <property name="age" value="11"/>
    </bean>
  </property>
</bean>

<!-- will result in 10, which is the value of property 'age' of bean 'testBean' -->
<util:property-path id="name" path="testBean.age"/>

The value of the 'path' attribute of the <property-path/> tag follows the form 'beanName.beanProperty'.

A.2.2.2.1. Using <util:property-path/> to set a bean property or constructor-argument

PropertyPathFactoryBean is a FactoryBean that evaluates a property path on a given target object. The target object can be specified directly or via a bean name. This value may then be used in another bean definition as a property value or constructor argument.

Here's an example where a path is used against another bean, by name:

// target bean to be referenced by name
<bean id="person" class="org.springframework.beans.TestBean" scope="prototype">
  <property name="age" value="10"/>
  <property name="spouse">
    <bean class="org.springframework.beans.TestBean">
      <property name="age" value="11"/>
    </bean>
  </property>
</bean>

// will result in 11, which is the value of property 'spouse.age' of bean 'person'
<bean id="theAge"
    class="org.springframework.beans.factory.config.PropertyPathFactoryBean">
  <property name="targetBeanName" value="person"/>
  <property name="propertyPath" value="spouse.age"/>
</bean>

In this example, a path is evaluated against an inner bean:

<!-- will result in 12, which is the value of property 'age' of the inner bean -->
<bean id="theAge"
    class="org.springframework.beans.factory.config.PropertyPathFactoryBean">
  <property name="targetObject">
    <bean class="org.springframework.beans.TestBean">
      <property name="age" value="12"/>
    </bean>
  </property>
  <property name="propertyPath" value="age"/>
</bean>

There is also a shortcut form, where the bean name is the property path.

<!-- will result in 10, which is the value of property 'age' of bean 'person' -->
<bean id="person.age"
    class="org.springframework.beans.factory.config.PropertyPathFactoryBean"/>

This form does mean that there is no choice in the name of the bean. Any reference to it will also have to use the same id, which is the path. Of course, if used as an inner bean, there is no need to refer to it at all:

<bean id="..." class="...">
  <property name="age">
    <bean id="person.age"
        class="org.springframework.beans.factory.config.PropertyPathFactoryBean"/>
  </property>
</bean>

The result type may be specifically set in the actual definition. This is not necessary for most use cases, but can be of use for some. Please see the Javadocs for more info on this feature.

A.2.2.3. <util:properties/>

Before...

<!-- creates a java.util.Properties instance with values loaded from the supplied location -->
<bean id="jdbcConfiguration" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
  <property name="location" value="classpath:com/foo/jdbc-production.properties"/>
</bean>

The above configuration uses a Spring FactoryBean implementation, the PropertiesFactoryBean, to instantiate a java.util.Properties instance with values loaded from the supplied Resource location).

After...

<!-- creates a java.util.Properties instance with values loaded from the supplied location -->
<util:properties id="jdbcConfiguration" location="classpath:com/foo/jdbc-production.properties"/>

A.2.2.4. <util:list/>

Before...

<!-- creates a java.util.List instance with values loaded from the supplied 'sourceList' -->
<bean id="emails" class="org.springframework.beans.factory.config.ListFactoryBean">
  <property name="sourceList">
      <list>
        <value>pechorin@hero.org</value>
        <value>raskolnikov@slums.org</value>
        <value>stavrogin@gov.org</value>
        <value>porfiry@gov.org</value>
      </list>
  </property>
</bean>

The above configuration uses a Spring FactoryBean implementation, the ListFactoryBean, to create a java.util.List instance initialized with values taken from the supplied 'sourceList'.

After...

<!-- creates a java.util.List instance with values loaded from the supplied 'sourceList' -->
<util:list id="emails">
    <value>pechorin@hero.org</value>
    <value>raskolnikov@slums.org</value>
    <value>stavrogin@gov.org</value>
    <value>porfiry@gov.org</value>
</util:list>

You can also explicitly control the exact type of List that will be instantiated and populated via the use of the 'list-class' attribute on the <util:list/> element. For example, if we really need a java.util.LinkedList to be instantiated, we could use the following configuration:

<util:list id="emails" list-class="java.util.LinkedList">
    <value>jackshaftoe@vagabond.org</value>
    <value>eliza@thinkingmanscrumpet.org</value>
    <value>vanhoek@pirate.org</value>
    <value>d'Arcachon@nemesis.org</value>
</util:list>

If no 'list-class' attribute is supplied, a List implementation will be chosen by the container.

Finally, you can also control the merging behavior using the 'merge' attribute of the <util:list/> element; collection merging is described in more detail in the section entitled 第 3.3.2.4.1 节 “集合的合并”.

A.2.2.5. <util:map/>

Before...

<!-- creates a java.util.Map instance with values loaded from the supplied 'sourceMap' -->
<bean id="emails" class="org.springframework.beans.factory.config.MapFactoryBean">
  <property name="sourceMap">
      <map>
        <entry key="pechorin" value="pechorin@hero.org"/>
        <entry key="raskolnikov" value="raskolnikov@slums.org"/>
        <entry key="stavrogin" value="stavrogin@gov.org"/>
        <entry key="porfiry" value="porfiry@gov.org"/>
      </map>
  </property>
</bean>

The above configuration uses a Spring FactoryBean implementation, the MapFactoryBean, to create a java.util.Map instance initialized with key-value pairs taken from the supplied 'sourceMap'.

After...

<!-- creates a java.util.Map instance with values loaded from the supplied 'sourceMap' -->
<util:map id="emails">
    <entry key="pechorin" value="pechorin@hero.org"/>
    <entry key="raskolnikov" value="raskolnikov@slums.org"/>
    <entry key="stavrogin" value="stavrogin@gov.org"/>
    <entry key="porfiry" value="porfiry@gov.org"/>
</util:map>

You can also explicitly control the exact type of Map that will be instantiated and populated via the use of the 'map-class' attribute on the <util:map/> element. For example, if we really need a java.util.TreeMap to be instantiated, we could use the following configuration:

<util:map id="emails" map-class="java.util.TreeMap">
    <entry key="pechorin" value="pechorin@hero.org"/>
    <entry key="raskolnikov" value="raskolnikov@slums.org"/>
    <entry key="stavrogin" value="stavrogin@gov.org"/>
    <entry key="porfiry" value="porfiry@gov.org"/>
</util:map>

If no 'map-class' attribute is supplied, a Map implementation will be chosen by the container.

Finally, you can also control the merging behavior using the 'merge' attribute of the <util:map/> element; collection merging is described in more detail in the section entitled 第 3.3.2.4.1 节 “集合的合并”.

A.2.2.6. <util:set/>

Before...

<!-- creates a java.util.Set instance with values loaded from the supplied 'sourceSet' -->
<bean id="emails" class="org.springframework.beans.factory.config.SetFactoryBean">
  <property name="sourceSet">
      <set>
        <value>pechorin@hero.org</value>
        <value>raskolnikov@slums.org</value>
        <value>stavrogin@gov.org</value>
        <value>porfiry@gov.org</value>
      </set>
  </property>
</bean>

The above configuration uses a Spring FactoryBean implementation, the SetFactoryBean, to create a java.util.Set instance initialized with values taken from the supplied 'sourceSet'.

After...

<!-- creates a java.util.Set instance with values loaded from the supplied 'sourceSet' -->
<util:set id="emails">
    <value>pechorin@hero.org</value>
    <value>raskolnikov@slums.org</value>
    <value>stavrogin@gov.org</value>
    <value>porfiry@gov.org</value>
</util:set>

You can also explicitly control the exact type of Set that will be instantiated and populated via the use of the 'set-class' attribute on the <util:set/> element. For example, if we really need a java.util.TreeSet to be instantiated, we could use the following configuration:

<util:set id="emails" set-class="java.util.TreeSet">
    <value>pechorin@hero.org</value>
    <value>raskolnikov@slums.org</value>
    <value>stavrogin@gov.org</value>
    <value>porfiry@gov.org</value>
</util:set>

If no 'set-class' attribute is supplied, a Set implementation will be chosen by the container.

Finally, you can also control the merging behavior using the 'merge' attribute of the <util:set/> element; collection merging is described in more detail in the section entitled 第 3.3.2.4.1 节 “集合的合并”.

A.2.3. The jee schema

The jee tags deal with JEE (Java Enterprise Edition)-related configuration issues, such as looking up a JNDI object and defining EJB references.

To use the tags in the jee schema, you need to have the following preamble at the top of your Spring XML configuration file; the emboldened text in the following snippet references the correct schema so that the tags in the jee namespace are available to you.

<?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:jee="http://www.springframework.org/schema/jee"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd">

<!-- <bean/> definitions here -->

</beans>

A.2.3.1. <jee:jndi-lookup/> (simple)

Before...

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/MyDataSource"/>
</bean>

<bean id="userDao" class="com.foo.JdbcUserDao">
    <!-- Spring will do the cast automatically (as usual) -->
    <property name="dataSource" ref="dataSource"/>
</bean>

After...

<jee:jndi-lookup id="dataSource" jndi-name="jdbc/MyDataSource"/>

<bean id="userDao" class="com.foo.JdbcUserDao">
    <!-- Spring will do the cast automatically (as usual) -->
    <property name="dataSource" ref="dataSource"/>
</bean>

A.2.3.2. <jee:jndi-lookup/> (with single JNDI environment setting)

Before...

<bean id="simple" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/MyDataSource"/>
    <property name="jndiEnvironment">
        <props>
            <prop key="foo">bar</prop>
        </props>
    </property>
</bean>

After...

<jee:jndi-lookup id="simple" jndi-name="jdbc/MyDataSource">
    <jee:environment>foo=bar</jee:environment>
</jee:jndi-lookup>

A.2.3.3. <jee:jndi-lookup/> (with multiple JNDI environment settings)

Before...

<bean id="simple" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/MyDataSource"/>
    <property name="jndiEnvironment">
        <props>
            <prop key="foo">bar</prop>
            <prop key="ping">pong</prop>
        </props>
    </property>
</bean>

After...

<jee:jndi-lookup id="simple" jndi-name="jdbc/MyDataSource">
    <!-- newline-separated, key-value pairs for the environment (standard Properties format) -->
    <jee:environment>
        foo=bar
        ping=pong
    </jee:environment>
</jee:jndi-lookup>

A.2.3.4. <jee:jndi-lookup/> (complex)

Before...

<bean id="simple" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/MyDataSource"/>
    <property name="cache" value="true"/>
    <property name="resourceRef" value="true"/>
    <property name="lookupOnStartup" value="false"/>
    <property name="expectedType" value="com.myapp.DefaultFoo"/>
    <property name="proxyInterface" value="com.myapp.Foo"/>
</bean>

After...

<jee:jndi-lookup id="simple"
             jndi-name="jdbc/MyDataSource"
             cache="true"
             resource-ref="true"
             lookup-on-startup="false"
             expected-type="com.myapp.DefaultFoo"
             proxy-interface="com.myapp.Foo"/>

A.2.3.5. <jee:local-slsb/> (simple)

The <jee:local-slsb/> tag configures a reference to an EJB Stateless SessionBean.

Before...

<bean id="simple"
      class="org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean">
  <property name="jndiName" value="ejb/RentalServiceBean"/>
  <property name="businessInterface" value="com.foo.service.RentalService"/>
</bean>

After...

<jee:local-slsb id="simpleSlsb" jndi-name="ejb/RentalServiceBean"
    business-interface="com.foo.service.RentalService"/>

A.2.3.6. <jee:local-slsb/> (complex)

<bean id="complexLocalEjb"
      class="org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean">
  <property name="jndiName" value="ejb/RentalServiceBean"/>
  <property name="businessInterface" value="com.foo.service.RentalService"/>
  <property name="cacheHome" value="true"/>
  <property name="lookupHomeOnStartup" value="true"/>
  <property name="resourceRef" value="true"/>
</bean>

After...

<jee:local-slsb id="complexLocalEjb"
    jndi-name="ejb/RentalServiceBean"
    business-interface="com.foo.service.RentalService"
    cache-home="true"
    lookup-home-on-startup="true"
    resource-ref="true">

A.2.3.7. <jee:remote-slsb/>

The <jee:remote-slsb/> tag configures a reference to a remote EJB Stateless SessionBean.

Before...

<bean id="complexRemoteEjb"
      class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean">
  <property name="jndiName" value="ejb/MyRemoteBean"/>
  <property name="businessInterface" value="com.foo.service.RentalService"/>
  <property name="cacheHome" value="true"/>
  <property name="lookupHomeOnStartup" value="true"/>
  <property name="resourceRef" value="true"/>
  <property name="homeInterface" value="com.foo.service.RentalService"/>
  <property name="refreshHomeOnConnectFailure" value="true"/>
</bean>

After...

<jee:remote-slsb id="complexRemoteEjb"
    jndi-name="ejb/MyRemoteBean"
    business-interface="com.foo.service.RentalService"
    cache-home="true"
    lookup-home-on-startup="true"
    resource-ref="true"
    home-interface="com.foo.service.RentalService"
    refresh-home-on-connect-failure="true">

A.2.4. The lang schema

The lang tags deal with exposing objects that have been written in a dynamic language such as JRuby or Groovy as beans in the Spring container.

These tags (and the dynamic language support) are comprehensively covered in the chapter entitled 第 24 章 动态语言支持 . Please do consult that chapter for full details on this support and the lang tags themselves.

In the interest of completeness, to use the tags in the lang schema, you need to have the following preamble at the top of your Spring XML configuration file; the emboldened text in the following snippet references the correct schema so that the tags in the lang namespace are available to you.

<?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:lang="http://www.springframework.org/schema/lang"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd">

<!-- <bean/> definitions here -->

</beans>

A.2.5. The jms schema

The jms tags deal with configuring JMS-related beans such as Spring's MessageListenerContainers. These tags are detailed in the section of the JMS chapter entitled 第 19.6 节 “JMS命名空间支持”. Please do consult that chapter for full details on this support and the jms tags themselves.

In the interest of completeness, to use the tags in the jms schema, you need to have the following preamble at the top of your Spring XML configuration file; the emboldened text in the following snippet references the correct schema so that the tags in the jms namespace are available to you.

<?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:jms="http://www.springframework.org/schema/jms"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-2.5.xsd">

<!-- <bean/> definitions here -->

</beans>

A.2.6. The tx (transaction) schema

The tx tags deal with configuring all of those beans in Spring's comprehensive support for transactions. These tags are covered in the chapter entitled 第 9 章 事务管理 .

提示

You are strongly encouraged to look at the 'spring-tx-2.5.xsd' file that ships with the Spring distribution. This file is (of course), the XML Schema for Spring's transaction configuration, and covers all of the various tags in the tx namespace, including attribute defaults and suchlike. This file is documented inline, and thus the information is not repeated here in the interests of adhering to the DRY (Don't Repeat Yourself) principle.

In the interest of completeness, to use the tags in the tx schema, you need to have the following preamble at the top of your Spring XML configuration file; the emboldened text in the following snippet references the correct schema so that the tags in the tx namespace are available to you.

<?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"
	   xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">

<!-- <bean/> definitions here -->

</beans>

注意

Often when using the tags in the tx namespace you will also be using the tags from the aop namespace (since the declarative transaction support in Spring is implemented using AOP). The above XML snippet contains the relevant lines needed to reference the aop schema so that the tags in the aop namespace are available to you.

A.2.7. The aop schema

The aop tags deal with configuring all things AOP in Spring: this includes Spring's own proxy-based AOP framework and Spring's integration with the AspectJ AOP framework. These tags are comprehensively covered in the chapter entitled 第 6 章 使用Spring进行面向切面编程(AOP) .

In the interest of completeness, to use the tags in the aop schema, you need to have the following preamble at the top of your Spring XML configuration file; the emboldened text in the following snippet references the correct schema so that the tags in the aop namespace are available to you.

<?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"
	   xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">

<!-- <bean/> definitions here -->

</beans>

A.2.8. The context schema

The context tags deal with ApplicationContext configuration that relates to plumbing - that is, not usually beans that are important to an end-user but rather beans that do a lot of grunt work in Spring, such as BeanfactoryPostProcessors. The following snippet references the correct schema so that the tags in the context namespace are available to you.

<?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:context="http://www.springframework.org/schema/context"
	   xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">

<!-- <bean/> definitions here -->

</beans>

注意

The context schema was only introduced in Spring 2.5.

A.2.8.1. <property-placeholder/>

This element activates the replacement of ${...} placeholders, resolved against the specified properties file (as a Spring resource location). This element is a convenience mechanism that sets up a PropertyPlaceholderConfigurer for you; if you need more control over the PropertyPlaceholderConfigurer, just define one yourself explicitly.

A.2.8.2. <annotation-config/>

Activates the Spring infrastructure for various annotations to be detected in bean classes: Spring's @Required and @Autowired, as well as JSR 250's @PostConstruct, @PreDestroy and @Resource (if available), and JPA's @PersistenceContext and @PersistenceUnit (if available). Alternatively, you can choose to activate the individual BeanPostProcessors for those annotations explictly.

注意

This element does not activate processing of Spring's @Transactional annotation. Use the <tx:annotation-driven/> element for that purpose.

A.2.8.3. <component-scan/>

This element is detailed in the section entitled 第 3.11 节 “基于注解(Annotation-based)的配置”.

A.2.8.4. <load-time-weaver/>

This element is detailed in the section entitled 第 6.8.4 节 “在Spring应用中使用AspectJ加载时织入(LTW)”.

A.2.8.5. <spring-configured/>

This element is detailed in the section entitled 第 6.8.1 节 “在Spring中使用AspectJ进行domain object的依赖注入”.

A.2.8.6. <mbean-export/>

This element is detailed in the section entitled 第 20.4.3 节 “<context:mbean-export/>元素”.

A.2.9. The tool schema

The tool tags are for use when you want to add tooling-specific metadata to your custom configuration elements. This metadata can then be consumed by tools that are aware of this metadata, and the tools can then do pretty much whatever they want with it (validation, etc.).

The tool tags are not documented in this release of Spring as they are currently undergoing review. If you are a third party tool vendor and you would like to contribute to this review process, then do mail the Spring mailing list. The currently supported tool tags can be found in the file 'spring-tool-2.5.xsd' in the 'src/org/springframework/beans/factory/xml' directory of the Spring source distribution.

A.2.10. The beans schema

Last but not least we have the tags in the beans schema. These are the same tags that have been in Spring since the very dawn of the framework. Examples of the various tags in the beans schema are not shown here because they are quite comprehensively covered in the section entitled 第 3.3.2 节 “依赖配置详解” (and indeed in that entire chapter).

One thing that is new to the beans tags themselves in Spring 2.0 is the idea of arbitrary bean metadata. In Spring 2.0 it is now possible to add zero or more key / value pairs to <bean/> XML definitions. What, if anything, is done with this extra metadata is totally up to your own custom logic (and so is typically only of use if you are writing your own custom tags as described in the appendix entitled 附录 B, Extensible XML authoring ).

Find below an example of the <meta/> tag in the context of a surrounding <bean/> (please note that without any logic to interpret it the metadata is effectively useless as-is).

<?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-2.5.xsd">

    <bean id="foo" class="x.y.Foo">
        <meta key="cacheName" value="foo"/>
        <property name="name" value="Rick"/>
    </bean>

</beans>

In the case of the above example, you would assume that there is some logic that will consume the bean definition and set up some caching infrastructure using the supplied metadata.

上一篇:下一篇: