<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
><channel><title>Himmel &#187; Spring</title> <atom:link href="http://lazing.ave7.net/tag/spring/feed/" rel="self" type="application/rss+xml" /><link>http://lazing.ave7.net</link> <description>时间很长；现在很短；距离很长；相遇很短</description> <lastBuildDate>Wed, 11 Jan 2012 18:03:14 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.2.1</generator> <creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license> <item><title>Spring 2.5 AOP Schema编程小解</title><link>http://lazing.ave7.net/2008/spring-25-aop-schema-urinate-programming/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=spring-25-aop-schema-urinate-programming</link> <comments>http://lazing.ave7.net/2008/spring-25-aop-schema-urinate-programming/#comments</comments> <pubDate>Fri, 22 Feb 2008 06:41:07 +0000</pubDate> <dc:creator>某L</dc:creator> <category><![CDATA[Tech Forge]]></category> <category><![CDATA[aop]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Spring]]></category> <category><![CDATA[xml]]></category><guid isPermaLink="false">http://lazing.ave7.net/blog/?p=241</guid> <description><![CDATA[AOP是已经是蔓延了好几年的话题，不过因为没有标准化的平台以及工具的缺乏，一直没有很好的推广。这里所用的AOP实现主要是Spring对AspectJ的封装。感谢Spring的出色贡献，我们甚至都不用知道什么是AspectJ就可以使用AOP概念进行程序设计和实现了。 AOP编程模型 通常情况下，程序中有很多公共的部分，比如事务控制，比如LOG记录。他们遍布程序各处，使代码凌乱不堪难以维护。AOP是对OOP一个很好的补充。OOP很好的描述了业务模型中各个组件的交互方式，但是对于系统组件的装配与互操作，却鲜有明确的定义。 下面就是这样的一个应用场景，对于一个业务方法，比如queryUserInfo我们都需要事务控制，日志记录。 从业务方法角度看AOP 在每一次调用业务方法时，AOP框架会使用around方式调用装配给业务方法的adviser..(可能更好理解的方式是类似 beforeMethod, afterMethod&#8230;)。 从Adviser看AOP 一个Adviser可能被装配给多个业务类的多个方法，通过不同的操作模型完成相关任务。 Spring 2.5 与AOP实现 下面通过一个非常简单的例子来说明Spring中AOP的Schema配置实现方式。 在此之前，应当对Spring 2.5 的Schema机制以及AOP AspectJ编程的一般概念有所了解。 请先阅读 Aspect Oriented Programming with Spring 关于AspectJ编程的相关概念及模式，请访问AspectJ website 下面是AOP的配置spring bean xml 文件 下面是 org.ave7.ws.aop.SystemMonitor 类的实现代码 package org.ave7.ws.aop; import org.aspectj.lang.ProceedingJoinPoint; import org.apache.commons.collections.LRUMap; import org.apache.commons.lang.builder.ReflectionToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import org.apache.commons.lang.time.DurationFormatUtils; import org.apache.commons.lang.time.StopWatch; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class SystemMonitor { <a href="http://lazing.ave7.net/2008/spring-25-aop-schema-urinate-programming/"> read more <span class="meta-nav">&#187;</span></a><br /><div><img src="http://lazing.ave7.net/wp-content/plugins/gd-star-rating/gfx.php?value=0.0" /></div><div>Rating: 0.0/<strong>5</strong> (0 votes cast)</div><br />]]></description> <content:encoded><![CDATA[<p>AOP是已经是蔓延了好几年的话题，不过因为没有标准化的平台以及工具的缺乏，一直没有很好的推广。这里所用的AOP实现主要是Spring对AspectJ的封装。感谢Spring的出色贡献，我们甚至都不用知道什么是AspectJ就可以使用AOP概念进行程序设计和实现了。</p><h4>AOP编程模型</h4><p>通常情况下，程序中有很多公共的部分，比如事务控制，比如LOG记录。他们遍布程序各处，使代码凌乱不堪难以维护。AOP是对OOP一个很好的补充。OOP很好的描述了业务模型中各个组件的交互方式，但是对于系统组件的装配与互操作，却鲜有明确的定义。</p><p>下面就是这样的一个应用场景，对于一个业务方法，比如queryUserInfo我们都需要事务控制，日志记录。</p><h5>从业务方法角度看AOP</h5><p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="258" alt="AOP  Example 1" src="http://lazing.ave7.net/" width="293" border="0"></p><p>在每一次调用业务方法时，AOP框架会使用around方式调用装配给业务方法的adviser..(可能更好理解的方式是类似 beforeMethod, afterMethod&#8230;)。</p><h5>从Adviser看AOP</h5><p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="154" alt="image" src="http://lazing.ave7.net/" width="363" border="0"></p><p>一个Adviser可能被装配给多个业务类的多个方法，通过不同的操作模型完成相关任务。</p><h4>Spring 2.5 与AOP实现</h4><p>下面通过一个非常简单的例子来说明Spring中AOP的Schema配置实现方式。</p><p>在此之前，应当对Spring 2.5 的Schema机制以及AOP AspectJ编程的一般概念有所了解。</p><p>请先阅读</p><ul><li><a href="http://static.springsource.org/spring/docs/2.5.x/reference/aop.html">Aspect Oriented Programming with Spring</a><li>关于AspectJ编程的相关概念及模式，请访问<a href="http://www.eclipse.org/aspectj/">AspectJ website</a></li></ul><p>下面是AOP的配置spring bean xml 文件</p><pre class="xml" name="code"><?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="<a href="http://www.springframework.org/schema/beans">http://www.springframework.org/schema/beans</a>" xsi:schemalocation="<a href="http://www.springframework.org/schema/beans">http://www.springframework.org/schema/beans</a> <a href="http://www.springframework.org/schema/beans/spring-beans.xsd">http://www.springframework.org/schema/beans/spring-beans.xsd</a>
		<a href="http://www.springframework.org/schema/aop">http://www.springframework.org/schema/aop</a> <a href="http://www.springframework.org/schema/aop/spring-aop.xsd">http://www.springframework.org/schema/aop/spring-aop.xsd</a>
		<a href="http://www.springframework.org/schema/tx">http://www.springframework.org/schema/tx</a> <a href="http://www.springframework.org/schema/tx/spring-tx.xsd">http://www.springframework.org/schema/tx/spring-tx.xsd</a>" xmlns:tx="<a href="http://www.springframework.org/schema/tx">http://www.springframework.org/schema/tx</a>" xmlns:aop="<a href="http://www.springframework.org/schema/aop">http://www.springframework.org/schema/aop</a>" xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>">
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		
		<tx:attributes>
			
			<tx:method name="get*" read-only="true" />
			<tx:method name="find*" read-only="true" />
			<tx:method name="page*" read-only="true" />
			<tx:method name="load*" read-only="true" />
			<tx:method name="query*" read-only="true" />
			
			<tx:method name="*" />
		</tx:attributes>
	</tx:advice>
	
	<bean class="org.ave7.ws.aop.SystemMonitor" id="systemMonitor">
	</bean>

	<aop:config>
		<aop:pointcut id="serviceMethods" expression="execution(* org.ave7.ws.service.impl.*.*(..))" />
		<aop:advisor pointcut-ref="serviceMethods" advice-ref="txAdvice" />
		
		<aop:aspect ref="systemMonitor">
			<aop:around pointcut-ref="serviceMethods" method="profileMethod" />
		</aop:aspect>
	</aop:config>

	
	<bean class="org.ave7.ws.service.impl.UserServiceImpl" id="userService">
	</bean>

</beans>
</pre><p>下面是 org.ave7.ws.aop.SystemMonitor 类的实现代码</p><pre name="code" class="java">
package org.ave7.ws.aop;

import org.aspectj.lang.ProceedingJoinPoint;

import org.apache.commons.collections.LRUMap;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.apache.commons.lang.time.DurationFormatUtils;
import org.apache.commons.lang.time.StopWatch;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class SystemMonitor {

    private static final LRUMap logMap = new LRUMap(100);

    // 参数call包含了被调用方法的相关信息，请参考ApectJ网站
    public Object profileMethod(ProceedingJoinPoint call) throws Throwable {
        Log log = obtainLogger(call.getTarget().getClass());
        if (log.isDebugEnabled()) {
            log.debug("call " + call.getSignature().toLongString());
            log.debug("with para: "
                    + ReflectionToStringBuilder.toString(call.getArgs(),
                            ToStringStyle.MULTI_LINE_STYLE, true));

            StopWatch watch = new StopWatch();

            watch.start();

            try {
                Object rt = call.proceed();

                log.debug("return : "
                        + ReflectionToStringBuilder.toString(rt,
                                ToStringStyle.MULTI_LINE_STYLE, true));
                return rt;
            } catch (Throwable e) {
                log.warn("exception: " + e.getMessage(), e);
                throw e;

            } finally {
                watch.stop();
                log.debug("executing time: "
                        + DurationFormatUtils.formatDuration(watch.getTime(),
                                "m:s.S"));

            }
        } else {
            return call.proceed();
        }

    }

    private Log obtainLogger(Class<?> clazz) {

        Log log = (Log) logMap.get(clazz);
        if (null == log) {
            log = LogFactory.getLog(clazz);
            logMap.put(clazz, log);
        }
        return log;
    }

}
</pre><ul><li><a href="http://lazing.ave7.net/2008/talk-about-easymock/" rel="bookmark" title="2008/02/10">说一下EasyMock</a></li><li><a href="http://lazing.ave7.net/2008/maven-need-to-act-as-wikipedia/" rel="bookmark" title="2008/05/23">Maven need to act as Wikipedia</a></li><li><a href="http://lazing.ave7.net/2007/xfire-and-spring-development-of-the-use-of-web-services/" rel="bookmark" title="2007/12/29">使用XFire与Spring开发Web Services</a></li><li><a href="http://lazing.ave7.net/2007/java-module-and-maven/" rel="bookmark" title="2007/12/06">Java Module and Maven</a></li><li><a href="http://lazing.ave7.net/2007/junit-unit-testing-and-integration-testing-guidelines/" rel="bookmark" title="2007/12/15">JUnit单元测试与集成测试指引</a></li></ul><p></p><p><a href="http://www.bshare.cn/share?url=http%3A%2F%2Flazing.ave7.net%2F2008%2Fspring-25-aop-schema-urinate-programming%2F&title=Spring+2.5+AOP+Schema%E7%BC%96%E7%A8%8B%E5%B0%8F%E8%A7%A3" title="用bShare分享或收藏本文"><img src="http://static.bshare.cn/frame/images/button_custom1-zh.gif" alt="用bShare分享或收藏本文" /></a></p><br /><div><img src="http://lazing.ave7.net/wp-content/plugins/gd-star-rating/gfx.php?value=0.0" /></div><div>Rating: 0.0/<strong>5</strong> (0 votes cast)</div><br /> <img src="http://lazing.ave7.net/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=241" width="1" height="1" style="display: none;" />]]></content:encoded> <wfw:commentRss>http://lazing.ave7.net/2008/spring-25-aop-schema-urinate-programming/feed/</wfw:commentRss> <slash:comments>1</slash:comments> <creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license> </item> <item><title>使用XFire与Spring开发Web Services</title><link>http://lazing.ave7.net/2007/xfire-and-spring-development-of-the-use-of-web-services/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=xfire-and-spring-development-of-the-use-of-web-services</link> <comments>http://lazing.ave7.net/2007/xfire-and-spring-development-of-the-use-of-web-services/#comments</comments> <pubDate>Sat, 29 Dec 2007 11:08:29 +0000</pubDate> <dc:creator>某L</dc:creator> <category><![CDATA[Code Jam]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Spring]]></category> <category><![CDATA[xfire]]></category><guid isPermaLink="false">http://lazing.ave7.net/blog/?p=263</guid> <description><![CDATA[下载PDF 使用XFire与Spring开发Web Service xfire-src 相关源码下载 实现功能与特点 基于J2EE平台的Web Service服务 开发方便，配置简单 设计接口 实现服务 配置暴露接口 XFire将自动生成对应的wsdl 支持高级详细配置 与Spring无缝集成 运行环境 JDK 1.4+ Tomcat 4.0+ / WebLogic 8.1 （需要特殊配置，见附录）未测试其他环境 其他包依赖参看 http://xfire.codehaus.org/Dependency+Guide 开发平台 Eclipse WTP 1.5 平台IDE：www.eclipse.org/webtools/ XFire 1.2.6 http://xfire.codehaus.org/Home 可以选择安装XFire for Eclipse插件，可以添加XFire相关类库，根据WSDL生成代码。http://xfire.codehaus.org/Eclipse+Plugin JDK 1.4.2 http://java.sun.com/products/archive/ Tomcat 5.0.28 http://tomcat.apache.org/download-55.cgi#5.0.28 Java Module and Maven Spring 2.5 AOP Schema编程小解 Java：利用XML生成Word文档 教学贴：如何编写Maven2插件 2008九月·学习主题·SOA Rating: <a href="http://lazing.ave7.net/2007/xfire-and-spring-development-of-the-use-of-web-services/"> read more <span class="meta-nav">&#187;</span></a><br /><div><img src="http://lazing.ave7.net/wp-content/plugins/gd-star-rating/gfx.php?value=0.0" /></div><div>Rating: 0.0/<strong>5</strong> (0 votes cast)</div><br />]]></description> <content:encoded><![CDATA[<p> 下载PDF 使用XFire与Spring开发Web Service</p><p>xfire-src 相关源码下载</p><h3><a name="_Toc175025960">实现功能与特点</a></h3><ul><li>基于J2EE平台的Web Service服务</li><li>开发方便，配置简单</li><li>设计接口</li><li>实现服务</li><li>配置暴露接口</li><li>XFire将自动生成对应的wsdl</li><li>支持高级详细配置</li><li>与Spring无缝集成</li></ul><h3><a name="_Toc175025961">运行环境</a></h3><ul><li>JDK 1.4+</li><li>Tomcat 4.0+ / WebLogic 8.1 （需要特殊配置，见附录）未测试其他环境</li><li>其他包依赖参看 <a href="http://xfire.codehaus.org/Dependency+Guide">http://xfire.codehaus.org/Dependency+Guide</a></li></ul><h3><a name="_Toc175025962">开发平台</a></h3><ul><li>Eclipse WTP 1.5 平台IDE：<a href="http://www.eclipse.org/webtools/">www.<strong>eclipse</strong>.org/webtools/</a></li><li>XFire 1.2.6 <a href="http://xfire.codehaus.org/Home">http://xfire.codehaus.org/Home</a></li><li>可以选择安装XFire for Eclipse插件，可以添加XFire相关类库，根据WSDL生成代码。<a href="http://xfire.codehaus.org/Eclipse+Plugin">http://xfire.codehaus.org/Eclipse+Plugin</a></li><li>JDK 1.4.2 <a href="http://www.oracle.com/technetwork/java/archive-139210.html">http://java.sun.com/products/archive/</a></li><li>Tomcat 5.0.28 <a href="http://tomcat.apache.org/download-55.cgi#5.0.28">http://tomcat.apache.org/download-55.cgi#5.0.28</a></li></ul><ul><li><a href="http://lazing.ave7.net/2007/java-module-and-maven/" rel="bookmark" title="2007/12/06">Java Module and Maven</a></li><li><a href="http://lazing.ave7.net/2008/talk-about-easymock/" rel="bookmark" title="2008/02/10">说一下EasyMock</a></li><li><a href="http://lazing.ave7.net/2009/teaching-paste-how-to-write-plug-ins-maven2/" rel="bookmark" title="2009/05/26">教学贴：如何编写Maven2插件</a></li><li><a href="http://lazing.ave7.net/2007/swap-away/" rel="bookmark" title="2007/03/20">Swap Away</a></li><li><a href="http://lazing.ave7.net/2007/preamble-lazingu002639s-java-guide/" rel="bookmark" title="2007/06/23">序言 &#8211; Lazing&#8217;s Java Guide</a></li></ul><p></p><p><a href="http://www.bshare.cn/share?url=http%3A%2F%2Flazing.ave7.net%2F2007%2Fxfire-and-spring-development-of-the-use-of-web-services%2F&title=%E4%BD%BF%E7%94%A8XFire%E4%B8%8ESpring%E5%BC%80%E5%8F%91Web+Services" title="用bShare分享或收藏本文"><img src="http://static.bshare.cn/frame/images/button_custom1-zh.gif" alt="用bShare分享或收藏本文" /></a></p><br /><div><img src="http://lazing.ave7.net/wp-content/plugins/gd-star-rating/gfx.php?value=0.0" /></div><div>Rating: 0.0/<strong>5</strong> (0 votes cast)</div><br /> <img src="http://lazing.ave7.net/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=263" width="1" height="1" style="display: none;" />]]></content:encoded> <wfw:commentRss>http://lazing.ave7.net/2007/xfire-and-spring-development-of-the-use-of-web-services/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license> </item> <item><title>JUnit单元测试与集成测试指引</title><link>http://lazing.ave7.net/2007/junit-unit-testing-and-integration-testing-guidelines/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=junit-unit-testing-and-integration-testing-guidelines</link> <comments>http://lazing.ave7.net/2007/junit-unit-testing-and-integration-testing-guidelines/#comments</comments> <pubDate>Sat, 15 Dec 2007 09:40:07 +0000</pubDate> <dc:creator>某L</dc:creator> <category><![CDATA[Tech Forge]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Spring]]></category> <category><![CDATA[unittest]]></category><guid isPermaLink="false">http://lazing.ave7.net/blog/?p=209</guid> <description><![CDATA[基于JUnit 3.8 与Spring 1.2环境的测试方法 本文将介绍使用JUnit结合Spring进行单元测试和集成测试的一般方法，并探讨基本的测试最佳实践，希望能够协助大家提高代码质量。本文属于介绍性质，文后附有相关书目，可以系统的了解xUnit框架详细的知识。 文中源码供参考使用。 和本站所有文章一样，使用非商业性-署名-内容一致 有限保留版权，请参看创作共享协议3.0版本 文章和源代码下载：<br /><div><img src="http://lazing.ave7.net/wp-content/plugins/gd-star-rating/gfx.php?value=0.0" /></div><div>Rating: 0.0/<strong>5</strong> (0 votes cast)</div><br />]]></description> <content:encoded><![CDATA[<p>基于JUnit 3.8 与Spring 1.2环境的测试方法</p><p>本文将介绍使用JUnit结合Spring进行单元测试和集成测试的一般方法，并探讨基本的测试最佳实践，希望能够协助大家提高代码质量。本文属于介绍性质，文后附有相关书目，可以系统的了解xUnit框架详细的知识。</p><p>文中源码供参考使用。</p><p>和本站所有文章一样，使用非商业性-署名-内容一致 有限保留版权，请参看创作共享协议3.0版本</p><p>文章和源代码下载：<a href="http://lazing.ave7.net/" title="JUnit&aring;<ul><li><a href="http://lazing.ave7.net/2008/talk-about-easymock/" rel="bookmark" title="2008/02/10">说一下EasyMock</a></li><li><a href="http://lazing.ave7.net/2008/java-scripting-in-jdk6/" rel="bookmark" title="2008/07/21">Java Scripting in JDK6</a></li><li><a href="http://lazing.ave7.net/2007/swap-away/" rel="bookmark" title="2007/03/20">Swap Away</a></li><li><a href="http://lazing.ave7.net/2008/java-generating-word-documents-using-xml/" rel="bookmark" title="2008/03/01">Java：利用XML生成Word文档</a></li><li><a href="http://lazing.ave7.net/2007/xfire-and-spring-development-of-the-use-of-web-services/" rel="bookmark" title="2007/12/29">使用XFire与Spring开发Web Services</a></li></ul><p></p><p><a href="http://www.bshare.cn/share?url=http%3A%2F%2Flazing.ave7.net%2F2007%2Fjunit-unit-testing-and-integration-testing-guidelines%2F&title=JUnit%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%E4%B8%8E%E9%9B%86%E6%88%90%E6%B5%8B%E8%AF%95%E6%8C%87%E5%BC%95" title="用bShare分享或收藏本文"><img src="http://static.bshare.cn/frame/images/button_custom1-zh.gif" alt="用bShare分享或收藏本文" /></a></p><br /><div><img src="http://lazing.ave7.net/wp-content/plugins/gd-star-rating/gfx.php?value=0.0" /></div><div>Rating: 0.0/<strong>5</strong> (0 votes cast)</div><br /> <img src="http://lazing.ave7.net/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=209" width="1" height="1" style="display: none;" />]]></content:encoded> <wfw:commentRss>http://lazing.ave7.net/2007/junit-unit-testing-and-integration-testing-guidelines/feed/</wfw:commentRss> <slash:comments>2</slash:comments> <creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license> </item> </channel> </rss>
