spring configuration based AOP xml

<?xml version="1.0" encoding="UTF-8"?>
<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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
https://www.springframework.org/schema/aop/spring-aop.xsd">

<!--配置spring的ioc,把service对象配置进来-->
<bean id="accountService" class="com.itheima.service.impl.AccountServiceImpl"></bean>

<!--spring configured based AOP xml of 2. aop: config configuration label indicates the beginning of AOP
1. notification Bean also managed to spring

3. aop: aspect tag indicates that the configuration section
id attribute: section is to provide a unique identifier
ref attribute: Specifies a notification bean class id
4. In aop: configuring corresponding tag type of the notification using the internal aspect tag
we let pringLog example is performed before the implementation of an entry point, so is the pre-notification
aop: before the pre-notification shows an arrangement
method attribute: used to specify the Logger class method is that before advice
pointcut attribute: used to specify the starting point expression style, the meaning of the expression refers to what methods to enhance the business layer

pointcut expressions wording:
keywords: execution (expression)
expression:
access modifier, return values, the package name registration .. package name. . the class name. method name (parameter list)
expression standard formula is written
public void com.itheima.service.impl.AccountServiceImpl.saveAccount ()
access modifier can be omitted
void com.itheima.service.impl.AccountServiceImpl.saveAccount ()
Return Value can use wildcards, represent any return value
* com.itheima.service.impl.AccountServiceImpl.saveAccount ()
package name can use wildcards, refers to any packet, but pack a few levels, it is necessary to write a few *.
* *. *. *. *. AccountServiceImpl.saveAccount ()
package name can be used .. represent the current package and its subpackages
* * .. AccountServiceImpl.saveAccount ()
class name and method names can be used to implement the wildcard *
* * .. * * () method only wildcard parameter-free method parameters.
parameter list:
you can write directly to the data type
. the basic types of direct write name int * * .. * * ( int)
Reference types write the package name. The name of the class method java.long.String * * .. *. * ( Java.long.String)
using wildcard represents any type, but there must be parameters * * .. *. * (*)
Use .. parameters can indicate whether there can be any type of parameter * * .. *. * (..)

all pass with the wording
* * .. *. * (..)

the actual development of the expression is usually the starting point writing:
cut method in all business layer implementation class
* * * com.itheima.service.impl (..)..
->

<- configuration class Logger ->!
<the bean ID = "Logger" class = "com.itheima.utils.Logger"> </ the bean>

! <- configuration AOP ->
<AOP: config>
<- configuration cut ->!
<AOP: Aspect ID = "logAdvice" REF = "Logger ">
<!- type configuration and associated notification of the notification method and the starting point of the method ->
<aop:before method="printLog" pointcut="execution(* *..*.*(..))"></aop:before>
</aop:aspect>
</aop:config>
</beans>

Guess you like

Origin www.cnblogs.com/lijiahaoAA/p/12284685.html