自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Spring AOP使用心得

開發(fā) 后端
本文介紹Spring AOP使用心得,以及在Spring的xml配置文件中加入新的schema。

畢竟是***次使用Spring AOP,按照Reference中的介紹,準(zhǔn)備使用Annotation來完成對AOP的配置。來看一下我做的步驟:

一、需要使用Spring2.0的jar包,現(xiàn)在已經(jīng)發(fā)布正式版的2.0了,可以從http://www.springframework.org/上下載到***的2.0版本。加入到項目的classpath中去。

二、需要在配置文件中啟用新的spring2.0的schema或者是dtd。  

1、在Spring的xml配置文件中加入新的schema:

  1. <beans xmlns="http://www.springframework.org/schema/beans" 
  2.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  3.     xmlns:aop="http://www.springframework.org/schema/aop" 
  4.     xmlns:tx="http://www.springframework.org/schema/tx" 
  5.     xsi:schemaLocation="http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans-2.0.xsd  
  6.            http://www.springframework.org/schema/aop                           http://www.springframework.org/schema/aop/spring-aop-2.0.xsd  
  7.            http://www.springframework.org/schema/tx                                
  8.     default-autowire="byName" default-lazy-init="true"> 

2、“如果使用Java 5的話,推薦使用Spring提供的@AspectJ切面支持,通過這種方式聲明Spring AOP中使用的切面。 "@AspectJ"使用了Java 5的注解,可以將切面聲明為普通的Java類?!薄猄pring reference

3、為了使用Spring AOP的Annotation,在配置文件中加入<aop:aspectj-autoproxy />。

4、編寫切面類:

  1. public class ArticleRemoteAccountsService {  
  2.    
  3.     /** *//**  
  4.      * 在發(fā)帖成功之后,給用戶銀幣賬戶沖值  
  5.      *   
  6.      * @param arg  
  7.      * @throws AccountsException  
  8.      * @throws InstantiationException  
  9.      * @throws IllegalAccessException  
  10.      */  
  11.     @After("execution(* com.company.ArticleManager.saveArticle(..))"  
  12.             + " && args(arg)")  
  13.     public void exSilByPost(Article arg) throws AccountsException,  
  14.             InstantiationException, IllegalAccessException {  
  15.         if (arg.getLastUpdateTime() == null  
  16.                 && arg.getArticleByParentId() == null  
  17.                 && arg.getArticleByRootId() == null) {  
  18.             // TODO 主題帖  
  19.         } else if (arg.getLastUpdateTime() == null  
  20.                 && (arg.getArticleByParentId() != null || arg  
  21.                         .getArticleByRootId() != null)) {  
  22.             // TODO  回帖  
  23.         }  
  24.     }  
  25. }  

這里需要注意的是使用Annotation的Poincut語法,execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern) throws-pattern?)這里就不累訴了。同時要注意的如何得到參數(shù)的問題,寫法參考如上。

 

【編輯推薦】

  1. Spring Batch 2.0的新特性
  2. 簡單介紹Spring osgi
  3. Spring OSGi的整合
  4. 在Spring中配置Glassfish JPA
  5. 解決Spring2.0向spring2.5遷移的問題
責(zé)任編輯:佚名 來源: blogjava
相關(guān)推薦

2011-01-19 14:57:09

Thunderbird

2011-01-07 11:14:17

Nginx負載均衡負載均衡

2010-02-01 10:15:07

C++ TinyXML

2011-09-01 10:16:43

JQuery Mobi

2009-06-26 16:12:08

ThickboxjQuery

2009-08-28 10:08:15

C# using語句

2010-03-02 17:33:49

Android 2.0

2009-08-31 10:00:07

C#靜態(tài)變量

2009-08-11 11:42:50

Ruby使用心得

2011-03-15 11:05:03

2010-06-01 13:42:37

TortoiseSVN

2011-04-20 13:59:28

愛普生V100掃描儀

2010-08-06 11:12:38

FlexCairngorm框架

2009-08-26 13:31:21

JavaScript使

2009-07-31 18:37:45

ASP.NET MVC

2020-03-16 08:13:58

SQL性能問題

2016-10-07 15:45:59

2022-06-27 19:16:53

Obsidian工具

2009-11-25 17:24:42

無線路由器

2021-03-01 23:26:41

日志Spring BootAOP
點贊
收藏

51CTO技術(shù)棧公眾號