首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

spring中load time weave的使用

2012-09-02 
spring中load time weave的应用??? 一直以来利用spring作为java程序开发的框架,在利用spring各种方便功能

spring中load time weave的应用

??? 一直以来利用spring作为java程序开发的框架,在利用spring各种方便功能的过程中,由于spring管理的bean的生成过程,所以对于一些设计模式的应用就受到了限制。

?? spring在2.0以后的版本中,引入了load time weave的概念,可以利用spring的配置文件管理bean的各种属性,在代码中利用@configurable标签标注配置的类,以后再代码中生成相应的bean,就可以得到两个方面的益处了:

?? 一是可以再代码中控制bean的生产过程;二是可以利用spring的配置和引用spring配置中的bean。

spring中的配置为:

<?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:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"><context:annotation-config/><context:load-time-weaver/><bean id ="spel" class = "org.tkxing.spring.spel.SpelObject"><property name="data" ref ="dataConfiguration"></property></bean><bean id ="host" class = "org.tkxing.spring.spel.HostObject" abstract="true"><property name="spel" ref="spel"></property></bean></beans>

?java中class的实现为:

import org.springframework.beans.factory.annotation.Configurable;@Configurable("host")public class HostObject {private String hello;private SpelObject spel;public String getHello() {return hello;}public void setHello(String hello) {this.hello = hello;}public SpelObject getSpel() {return spel;}public void setSpel(SpelObject spel) {this.spel = spel;}}

?

热点排行