Interceptor is an interceptor that can listen to the entire program or method of a program. It is often easier to understand problems from multiple programs, and I have added interceptor on the basis of the HelloWorld program I write myself.
There are several programs: Hello.java, Hellolocal.java, Helloremote.java, Hellobean.java, Tracinginterceptor.java
Client.java
Focus on Hellobean.java, Tracinginterceptor.java these two programs.
The above two monitoring of the entire class situation, more to do is to monitor individual interception of each method separately, need to write a different method:
@AroundInvoke
The public Object method name can be arbitrary (Invocationcontext ctx) throws Exception
{
}
Tracinginterceptor.java
Package Org.jboss.tutorial.stateless.bean;
Import Javax.ejb.AroundInvoke;
Import Javax.ejb.InvocationContext;
public class Tracinginterceptor {
@AroundInvoke
Public Object log (Invocationcontext ctx) throws Exception
In the client program incredibly no interceptor traces, hehe. The point to note here is hello, where the output of the Hello2 method is different, one in the build Ant window and the other in the JBoss run window.
Here attached log4j.properties in Jboss-ejb-3.0_preview_5.zip without this always shows a lack of appender. With this, a record.log log file will be generated in this directory.
To run this program, you can combine it with the jboss-ejb-3.0_preview_5.zip, and change target run on the Build.xml file.
Under Windows
Open command Prompt cmd, to Jboss_home/bin
Run.bat–c All
With Ant
Just build and run.
Discuss:
In many places I can see interceptor, the first thing I saw in AOP. The example of the interceptor in Jboss-ejb-3.0_preview_5.zip may be to integrate some of the knowledge in the context of what has been learned before. It is not difficult to understand, here I just break it down, easier to see and master.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.