This paper mainly analyzes the plug-in mechanism of mybatis, in fact, is the implementation of the responsibility chain model of Java dynamic Proxy implementation.
According to the official document. MyBatis only allows you to intercept the following methods, this decision writes the Interceptor annotation signature parameter.
The code is as follows
Copy Code
Executor (update,
This article is from: Cao shenghuan blog column. Reprinted please indicate the source:Http://blog.csdn.net/csh624366188
Interceptor is one of struts2's most powerful features. It can also be said to be the core of struts2. It allows you to process the action or result before or after it is executed. At the same time, the interceptor allows you to modularize common code and use it as a reusable class. Many
request does not continue to pass down, directly along the chain back run. - * 2. When the Prehandle method is all true, the next interceptor is executed until all interceptors are executed. Run the intercepted controller again. - * Then go into the interceptor chain, run all the Interceptor's Posthandle method, and then execute the Aftercompletion method of all interceptors back from the last
reflection mechanism of the Java itself, which is the most essential difference between the two. Two, filter is dependent on the servlet container, which can only be performed in the servlet container, and it is clear that there is no servlet container to adjust the Dofilter method back and forth. Interceptor is not related to the servlet container. Comparison III, filter filtering range than
The class of the dynamic proxy that comes with Java must implement an interface, and it is said that the use of reflection is not very efficient. So the Cglib was born.The use of Cglib to implement dynamic proxy, completely non-agent class must implement the interface constraints, and cglib based on ASM bytecode generation framework, using bytecode technology to generate proxy classes, in theory, than using Java
as some parameters or some fixed objects and so on.3. InterceptorsInterceptors are applied in aspect-oriented programming, either by invoking a method before your service or a method, or by invoking a method after the method. Is a Java-based reflection mechanism. Interceptors are not configured in Web. XML, such as struts, in Struts.xml. Filter: When you have a bunch of things, you just want to choose something that meets your requirements. The tool
Poor memory: 48-java Interceptor-Comparison of built-in dynamic proxies and CGLIB in JDK (3), 48-javacglib
The dynamic proxy class in Java must implement an interface, and it is said that reflection is not very efficient. Then CGLIB was born.Using CGLib to implement dynamic proxy is not restricted by the interface that the proxy class must implement. Besides, CG
: Introspectorcleanuplistener should be registered as the first listener in Web. XML, registered before any other listener, such as before Spring's contextloaderlistener registration To ensure that introspectorcleanuplistener takes effect at the right time in the life cycle of the Web App.listener> listener-class>org.springframework.web.util.introspectorcleanuplistenerlistener-class > listener>Third, Spring InterceptorSpring-managed interceptors need to inherit Intercepter implements
, I have something to look for first!CGLIB before:public java.lang.String com. CGLib.WangBaoQiang.getName ()I'm his agent, I have something to look for first!CGLIB after: End.Wangbaoqiang began to sing the world No Thief song!!CGLIB after: End.Singing is over, thank you!CGLIB before:public java.lang.String com. CGLib.WangBaoQiang.dance (java.lang.String)I'm his agent, I have something to look for first!CGLIB before:public java.lang.String com. CGLib.WangBaoQiang.getName ()I'm his agent, I have s
This example describes the Java custom interceptor and its usage. Share to everyone for your reference. Specifically as follows:
Logininterceptor.java files are as follows:
Package com.tq365.util;
Import Javax.servlet.http.HttpServletRequest;
Import javax.servlet.http.HttpSession;
Import Org.apache.struts2.ServletActionContext;
Import com.opensymphony.xwork2.ActionInvocation;
Import Com.opensymphony.x
Interceptors are common in popular open source frameworks, and rely on technologies that are dynamic proxies for Java.
Understanding the core principles of interceptors is critical to understanding the architecture of these open source frameworks.
The following is a simple model to illustrate the general approach to the implementation of the Interceptor.
The model is divided into the following modules:
Bus
agent, and have something to look for me first!" ");//proxy object invokes the Sing method of the real target object to process the user request returnMethod.invoke (actor, args); }if(Method.getname (). Equals ("Dance")) {//proxy object invokes the dance method of the real target object to process the user requestSystem.out.println ("I am his agent, and have something to look for me first!" ");returnMethod.invoke (actor, args); }return NULL; } }); }}
Multiple filter executions are performed according to the filter order configured in the configuration file.Configuring the filter in the Web. xml file, using the Init-param element to configure the parameter for the filter, Init-param accepts the following two child elements:Param-name: Specifies the name of the parameter.Param-value: Specifies the parameter value.Filter, filter-mapping, servlet, servlet-mapping constitute a complete interceptor conf
Bad memory: 47-java Interceptor-implement dynamic proxy with CGLib (2), 47-javacglib
Dynamic proxy technology is a very important part of the entire java technical system. It is the basis for us to learn more about the java framework and one of the basic knowledge we need to know about Spring and other frameworks.The
Struts2 interceptor is a good tool! In particular, the custom Interceptor. The following is a detailed process that I personally organized. I hope to help you and provide valuable opinions.
Principle:
A) The Web browser sends a request
B) First, use a set of Struts2 default interception stack dispatcher (or ServletFilter)
C) custom interceptor (
1. interceptor and interceptor stack 1. the interceptor's role is essentially the same as the servlet filter. In struts2, the interceptor can intercept the Action before and after the Action. The Interceptor is pluggable. You can choose to use the interceptor or uninstall th
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.