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
旱頭憨腦
閱讀(972)
評論(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 © 旱頭憨腦
主站蜘蛛池模板:
成a人片亚洲日本久久
|
亚洲春黄在线观看
|
免费中文字幕视频
|
日本19禁啪啪无遮挡免费动图
|
亚洲国产成人精品无码区在线秒播
|
6080午夜一级毛片免费看6080夜福利
|
亚洲精品一品区二品区三品区
|
91在线免费视频
|
亚洲精品无码MV在线观看
|
a级毛片免费高清毛片视频
|
亚洲午夜未满十八勿入网站2
|
久久精品成人免费国产片小草
|
亚洲无人区一区二区三区
|
国产免费牲交视频免费播放
|
亚洲色成人网站WWW永久
|
日本高清免费观看
|
666精品国产精品亚洲
|
18禁网站免费无遮挡无码中文
|
亚洲小说区图片区
|
在线免费观看一区二区三区
|
色欲色欲天天天www亚洲伊
|
亚洲Av无码乱码在线观看性色
|
国产免费内射又粗又爽密桃视频
|
亚洲av福利无码无一区二区
|
成人浮力影院免费看
|
日本系列1页亚洲系列
|
日韩精品亚洲aⅴ在线影院
|
精品国产免费人成电影在线观看
|
中国china体内裑精亚洲日本
|
亚洲成A人片77777国产
|
国产免费拔擦拔擦8X高清在线人
|
亚洲熟妇无码久久精品
|
免费A级毛片在线播放不收费
|
中文字幕在线免费视频
|
亚洲国产综合精品
|
免费在线观看亚洲
|
午夜理伦剧场免费
|
亚洲av综合av一区二区三区
|
亚洲爆乳无码一区二区三区
|
嫩草影院在线免费观看
|
中文字幕免费不卡二区
|