Spring AOP facet-oriented programming: How to make a powerful logging feature

Source: Internet
Author: User
Tags aop new features xmlns

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

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.