Spring2.0 AOP使用心得(一)
??????正在做的項目中有一個類似積分的需求,比如用戶在討論區發帖后,需要給一定的積分這樣的需求。因為需求是變化的,同時為了使已經寫好的發帖代碼不被入侵,所以考慮使用Spring2.0 AOP來實現這個功能。
??????畢竟是第一次使用Spring2.0的AOP,按照Reference中的介紹,準備使用Annotation來完成對AOP的配置。來看一下我做的步驟:
??????一、需要使用Spring2.0的jar包,現在已經發布正式版的2.0了,可以從
http://www.springframework.org/
? 上下載到最新的2.0版本。加入到項目的classpath中去。
????? 二、需要在配置文件中啟用新的spring2.0的schema或者是dtd。???
??????1、在Spring的xml配置文件中加入新的schema:
<
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.0.xsd
???????????http://www.springframework.org/schema/aop?http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
???????????http://www.springframework.org/schema/tx?http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
????default-autowire
="byName"
?default-lazy-init
="true"
>
?????? 2、“如果使用Java 5的話,推薦使用Spring提供的@AspectJ切面支持,通過這種方式聲明Spring AOP中使用的切面。 "@AspectJ"使用了Java 5的注解,可以將切面聲明為普通的Java類。”——Spring reference
??????3、為了使用AOP的Annotation,在配置文件中加入<aop:aspectj-autoproxy />。
??????4、編寫切面類:
@Aspect
public
?
class
?ArticleRemoteAccountsService?
{
?
????
/**?*/
/**
?????*?在發帖成功之后,給用戶銀幣賬戶沖值
?????*?
?????*?
@param
?arg
?????*?
@throws
?AccountsException
?????*?
@throws
?InstantiationException
?????*?
@throws
?IllegalAccessException
?????
*/
????@After(
"
execution(*?com.company.ArticleManager.saveArticle(..))
"
????????????
+
?
"
?&&?args(arg)
"
)
????
public
?
void
?exSilByPost(Article?arg)?
throws
?AccountsException,
????????????InstantiationException,?IllegalAccessException?
{
????????
if
?(arg.getLastUpdateTime()?
==
?
null
????????????????
&&
?arg.getArticleByParentId()?
==
?
null
????????????????
&&
?arg.getArticleByRootId()?
==
?
null
)?
{
????????????
//
?TODO 主題帖
????????}
?
else
?
if
?(arg.getLastUpdateTime()?
==
?
null
????????????????
&&
?(arg.getArticleByParentId()?
!=
?
null
?
||
?arg
????????????????????????.getArticleByRootId()?
!=
?
null
))?
{
????????????
//
?TODO? 回帖
????????}
????}
}
這里需要注意的是使用Annotation的Poincut語法,
execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern)
throws
-pattern?)
這里就不累訴了。
同時要注意的如何得到參數的問題,寫法參考如上。
posted on 2006-10-20 11:02
旱頭憨腦
閱讀(975)
評論(0)
編輯
收藏
所屬分類:
j2ee
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
相關文章:
Javascript cookie操作攻略
Spring2.0 AOP 心得(二)
Spring2.0 AOP使用心得(一)
Tomcat中,UTF-8 URL提交參數中文解決終極方案
Struts中不限個數上傳文件的實現方案
Spring2.0 新特性之Bean新增范圍session, request, global session
旱頭憨腦
lanluquan
導航
BlogJava
首頁
新隨筆
聯系
聚合
管理
統計
隨筆 - 1
文章 - 10
評論 - 1
引用 - 0
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(1)
給我留言
查看公開留言
查看私人留言
隨筆檔案
■
2006年10月 (1)
文章分類
■
ajax(1)
(rss)
■
j2ee(7)
(rss)
■
java
(rss)
■
ruby(1)
(rss)
■
非技術(1)
(rss)
文章檔案
■
2008年6月 (1)
■
2007年9月 (1)
■
2007年7月 (1)
■
2006年10月 (4)
■
2006年9月 (1)
■
2006年8月 (2)
搜索
最新評論
1.?re: Hibernate3 父子映射報錯:illegal access to loading collection
評論內容較長,點擊標題查看
--d
Powered by:
BlogJava
Copyright © 旱頭憨腦
主站蜘蛛池模板:
日本xxwwxxww在线视频免费
|
黄页网址在线免费观看
|
中文字幕成人免费视频
|
在线观看H网址免费入口
|
亚洲国产精久久久久久久
|
久久不见久久见免费视频7
|
亚洲av无码不卡
|
亚洲欧美国产欧美色欲
|
日韩精品免费一线在线观看
|
91高清免费国产自产拍2021
|
亚洲天堂中文字幕
|
可以免费看黄的网站
|
亚洲精品无码av片
|
99re免费在线视频
|
亚洲精品专区在线观看
|
国产乱妇高清无乱码免费
|
亚洲香蕉网久久综合影视
|
国产成人精品一区二区三区免费
|
亚洲色图黄色小说
|
国产精品免费看久久久香蕉
|
免费一本色道久久一区
|
亚洲国产美国国产综合一区二区
|
中文字幕亚洲免费无线观看日本
|
美女视频黄免费亚洲
|
免费精品国产自产拍观看
|
国产成人精品免费视频大全
|
香蕉视频在线观看亚洲
|
99视频在线精品免费观看6
|
337P日本欧洲亚洲大胆艺术图
|
久久亚洲av无码精品浪潮
|
99久热只有精品视频免费看
|
亚洲国产系列一区二区三区
|
免费很黄很色裸乳在线观看
|
精品成人免费自拍视频
|
亚洲人成人77777网站
|
久久久久高潮毛片免费全部播放
|
亚洲永久在线观看
|
丁香花免费完整高清观看
|
久久精品国产亚洲AV久
|
在线a级毛片免费视频
|
久香草视频在线观看免费
|