What does this thing do: Spring AOP How to make a powerful logging feature template for aspect-oriented programming;
Yesterday, the manager gave me this task, let me for the company's current project with a detailed logging function template, for all operations, at least add or delete the operation of a record, it to record the operator, as well as the implementation of methods, IP, as well as the operation of the parameters of the method.
I have done similar functions before, but I do it in filter, check the action request by filter, record the parameters and the action name in the request. But today the company is asking to do it with spring AOP, This allows you to make a configuration of the logging methods that you want to do in spring. And this can be seamlessly integrated into the existing system.
However, it is frustrating that I have not done so, or similar functions.
==========================
Haha, very cool, incredibly let me do it.
In fact, it's easy to use AOP's @aspectj to do it, and the method steps are as follows:
The first:>> adds the following configuration to the spring configuration file
<!-- 支持 @AspectJ 标记-->
<aop:aspectj-autoproxy />
If you find that eclipse prompts you for an error after inserting, it may be that your spring configuration has a problem, and you compare the head of the beans in my spring:
<?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"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
default-autowire="byName" default-lazy-init="true">
For spring and AOP and @aspectj configurations, please refer to my collection of the following articles
One of spring AOP based on @aspectj configuration ==>http://www.busfly.cn/csdn/post/700.html
The new features of Spring 2.0 @aspectj==>http://www.busfly.cn/csdn/post/699.html
AspectJ How to realize aop==>http://www.busfly.cn/csdn/post/698.html
AOP implementation-aspectj-advice==>http://www.busfly.cn/csdn/post/693.html in Spring 2.0