Basic XML configuration with a detailed comparison of AOP AOP-based implementation notes

aop thought through dynamic agent, to a certain extent to achieve a decoupling of the code. We can log module, check permissions, modules and other things, with the core business code isolated from the programmer when writing code, to be more focused on business.

Annotation-based AOP implementation steps:

① the target class and the class is added to the section ioc container.
The goal of the class with annotation with Han Han, cut class usually @Componentcan be. In addition, remember to scan applicationContext.xml configuration package file.
② for the section marked @Aspect class notes, tell Spring which is cut class.
③ In various notification method aspect class denoted annotations, and configure pointcut expression, the number of high spring when and where these notification methods are performed.
④ open the annotation-based AOP functionality.<aop:aspectj-autoproxy/>

The above operation, we may be more familiar with the way of development, after all, notes a lot easier configuration compared to the lot. However, xml configuration has its own advantages, it is more perfect. For example, a third-party jar package, when I need to refer to a section in which the class, notes the way it is somewhat hard for. xml configuration can be a good complement this.
In addition, an important aspect classes, usually in the habit of placing the xml configuration, such important rights verification, isolation and other things.

Xml configuration based AOP step of:
① bean configuration
of all components added to the ioc container, label management bean using the configuration file.

<bean id="xxx1" class="xxxx1"/>

② designated section
corresponds @Aspect notes, we need to configure class section in the aop namespace
for each <aop:aspect>tag is equivalent to a @Aspect annotation, attribute ref to fill <bean>the id tag cut class.

<aop:config>
	<aop:aspect ref="xxx1">
	</aop:aspect>
</aop:config>

③ configure the notification method
continues at the second step <aop:aspect>arranged inside tag notification method corresponding to the label, with almost exactly the same naming annotated. Method for the notification method of the aspect class; the pointcut expression as a starting point; returning return parameter specifies the return notification; abnormal parameter specifies the throwing abnormality notification.

<aop:config>
	<aop:aspect ref="xxx1">
		<aop:before method="" pointcut="">
		<aop:after method="" pointcut="">
		<aop:after-returning method="" pointcut="" returning="">
		<aop:after-throwing method="" pointcut="" throwing="">
		<aop:around method="" pointcut="">
	</aop:aspect>
</aop:config>

④ open the annotation-based AOP functionality. <aop:aspectj-autoproxy/>

Published 98 original articles · won praise 13 · views 20000 +

Guess you like

Origin blog.csdn.net/qq_41885819/article/details/104798823