Example explanation of log management by spring AOP custom annotation

Today, we continue to implement AOP. So far, I personally think it is the most flexible and extensible way. Take log management as an example. Use spring AOP custom annotation to realize log management. No more nonsense, start directly!!!

I'll say it again about configuration.

In ApplicationContext MVC XML to add

Next, start writing code.

Create log class entity

Write Dao interface

Write service layer

Write the service implementation class serviceimpl

Here, the basic program has been written

Let's start customizing annotations

Write the section below

I have written quite a lot here, including pre notification, surround notification, post notification, exception notification and post meal notification. It's ok if we don't write them all in our actual writing. I'm used to writing the logic of recording logs in the post notification. I think there are some in the pre notification on the Internet, but I think it's better to write them in the post notification.

Now start adding custom comments in the controller!!

Write the test class below

Database data:

I originally wanted to write two pointcuts, one is the service layer and the other is the controller layer. The service layer is used to record the log of exception information, while the controller layer is used to record the log of function. The operation results are as follows.

If you do this, you don't know whether the operation efficiency in the actual project is good or not. Please see Daniel of the blog here for some suggestions!!

The above example of implementing log management by spring AOP custom annotation is all the content shared by Xiaobian. I hope it can give you a reference and support more programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>