呃...吃太多, 有點消化不良, 先吐一點出來, 晚點在反芻... orz
1. Create a interface
package com.cht.domain;
public interface IWorker {
public void work(String thing);
public void sayHello(String who);
}
2. implement it
package com.cht.domain;
public class Employee implements IWorker{
@Override
public void work(String thing) {
System.out.println("\tDo " + thing);
}
@Override
public void sayHello(String who) {
System.out.println("\tHi, " + who);
}
}
3. write the aspect config bean
package com.cht.domain;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class AspectConfigBean {
@Pointcut("execution(* com.cht.domain.Employee.*(..))")
public void doIt() {
System.out.println("wwwwwwwwwhat!");
}
@Before("doIt()")
public void beforeExec(){
System.out.println("Before All function call...");
}
@Before("execution(* com.cht.domain.Employee.sayHello(..))")
public void beforeAgain(JoinPoint point){
System.out.println("Before Employee.sayHello");
}
@After("doIt()")
public void afterAll(JoinPoint point) {
System.out.println("All after "+ point.getSignature().getName());
}
@After("execution(* com.cht.domain.Employee.work(..))")
public void afterExecWork(JoinPoint point){
System.out.println("after "+ point.getSignature().getName());
}
@After("execution(* com.cht.domain.Employee.sayHello(..))")
public void afterExecSayHello(JoinPoint point ){
System.out.println("after "+ point.getSignature().getName());
}
@Around("execution(* com.cht.domain.Employee.*(..))")
public void aroundAdvice(ProceedingJoinPoint point){
System.out.println(point.getSignature().getName() + " proceeding...");
try {
point.proceed();
} catch (Throwable e) {
e.printStackTrace();
}
}
}
4. define them in the application context xml
<beans xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<aop:aspectj -autoproxy="-autoproxy" />
<bean class="com.cht.domain.Employee" id="employee" />
<bean class="com.cht.domain.AspectConfigBean" id="aspectBean" />
</beans>
5. test
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.cht.domain.IWorker;
public class TESTAOP {
public static void main(String[] args) {
ApplicationContext context =
new ClassPathXmlApplicationContext("spring-aop.xml");
IWorker worker = (IWorker) context.getBean("employee");
worker.sayHello("Samuel");
worker.work("programming");
}
}
It is truly a nice and useful piece of information.
回覆刪除I am happy that you just shared this useful info with us.
Please keep us up to date like this. Thanks for sharing.
My page : lan.helsingkrona.Se
For latest news you have to pay a visit internet and on world-wide-web I found this website as a finest website for newest updates.
回覆刪除Also visit my web-site : Fast Loan 1080
magnificent points altogether, you simply gained a new reader.
回覆刪除What could you recommend in regards to your submit that you made some days in the
past? Any sure?
My website : http://phpfoxdev.indexcreativeonline.com/
Thanks a bunch for sharing this with all of us you actually know what you are speaking about!
回覆刪除Bookmarked. Please also seek advice from my website =).
We can have a hyperlink change contract between us
Also visit my page http://Wiki.Space-Cam.ch/
Your style is so unique compared to other people I've read stuff from. Many thanks for posting when you have the opportunity, Guess I'll just book mark this blog.
回覆刪除Look at my weblog :: mikelim.info
Heya i'm for the first time here. I found this board and I find It really helpful & it helped me out much. I am hoping to give one thing again and aid others such as you aided me.
回覆刪除Here is my weblog ; businessnews.lu
I was curious if you ever thought of changing the layout of your blog?
回覆刪除Its very well written; I love what youve got to say. But maybe
you could a little more in the way of content so people could connect with it better.
Youve got an awful lot of text for only having one
or two images. Maybe you could space it out better?
My web page > Quick Payday Loans
Thank you for the good writeup. It in fact was a amusement account it.
回覆刪除Look advanced to more added agreeable from you!
However, how can we communicate?
Here is my website Blog.Phirmaza.Com
What's Taking place i am new to this, I stumbled upon this I have discovered It absolutely helpful and it has aided me out loads. I am hoping to give a contribution & aid other users like its helped me. Great job.
回覆刪除My site > Quick Loan
I'm not sure exactly why but this blog is loading very slow for me. Is anyone else having this problem or is it a problem on my end? I'll check back later on and see if the problem
回覆刪除still exists.
Look at my blog post :: Flippedeye.net
Greetings! Very useful advice within this article! It's the little changes which will make the most important changes. Thanks a lot for sharing!
回覆刪除Feel free to surf my web-site - fast cash loan 444
I don't even know how I stopped up here, however I believed this publish was once great. I don't know who you're but definitely you're going to a famous blogger when you
回覆刪除are not already. Cheers!
My web blog http://Mymotorcyclemonster.com/index.php?do=/sondravrcq/info
I do not even know how I stopped up here, however I thought this submit was once
回覆刪除good. I don't recognise who you might be but definitely you are going to a well-known blogger if you happen to are not already. Cheers!
Here is my weblog ... Http://andenipartners.Com/node/26417
Hi there great blog! Does running a blog
回覆刪除like this require a great deal of work? I've virtually no understanding of computer programming but I was hoping to start my own blog soon. Anyhow, if you have any ideas or techniques for new blog owners please share. I understand this is off subject but I just needed to ask. Many thanks!
Check out my blog - quick loan
Link exchange is nothing else however it is simply placing the other
回覆刪除person's blog link on your page at suitable place and other person will also do same in support of you.
Feel free to surf my web page psadirectory.cdconline.com
I was curiοuѕ if yоu eνer considered changing the layout of your ωebsite?
回覆刪除Its veгу wеll ωritten; I love
what youve got to say. But maybе you cοuld а little morе
in the wаy of content so people could connect with it better.
Youve got an awful lot of text for only having one oг two images.
Maybe you could space it out better?
My page: prosperloans.webstarts.com
Good post! We are linking to this great content on our site.
回覆刪除Keep up the great writing.
Here is my page :: buy targeted facebook likes australia