If you want to monitor all the ways to enter controller, Mengxin is not very good at it.

wants to monitor all methods that enter controller, but the aop class written by myself doesn"t work

tried to do it using the profile method and the annotation method, but did not enter the method.

related codes

package com.detain.system.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.detain.system.service.SystemService;

@Component
@Aspect
public class OperationRecordLog {
    
    @Autowired
    private SystemService systemService;
    
    @Around(value = "execution(* com.detain.*.action.*.*(..))")
    public Object exec(ProceedingJoinPoint invocation) throws Throwable {
        Object result = invocation.proceed();
        String name = invocation.getSignature().getName();
        String args = invocation.getArgs().toString();
        return result;
    }
}


wants to monitor all the methods that enter the controller. After execution, record the relevant parameters, but after running the program, the exec
method has never been executed. I would like to ask how to modify it.

Nov.22,2021

maybe it is more appropriate to use spring interceptor to do this

such as

package com.vaannila.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler. HandlerInterceptorAdapter;

public class LoggerInterceptor extends HandlerInterceptorAdapter {

    static Logger logger = Logger.getLogger(LoggerInterceptor.class);

    static{
        BasicConfigurator.configure();
    }
    
    @Override
    public boolean preHandle(HttpServletRequest request,
            HttpServletResponse response, Object handler) throws Exception {
        logger.info("Before handling the request");
        return super.preHandle(request, response, handler);
    }
    
    @Override
    public void postHandle(HttpServletRequest request,
            HttpServletResponse response, Object handler,
            ModelAndView modelAndView) throws Exception {
        logger.info("After handling the request");
        super.postHandle(request, response, handler, modelAndView);
    }
    
    @Override
    public void afterCompletion(HttpServletRequest request,
            HttpServletResponse response, Object handler, Exception ex)
            throws Exception {
        logger.info("After rendering the view");
        super.afterCompletion(request, response, handler, ex);
    }
}

configure

<?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:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="viewResolver" class="org.springframework.web.servlet.view. InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
    
    <bean id="handlerMapping" class="org.springframework.web.servlet.handler. BeanNameUrlHandlerMapping" p:interceptors-ref="loggerInterceptor" />
    
    <bean id="loggerInterceptor" class="com.vaannila.interceptor.LoggerInterceptor" />
    
    <bean id="userService" class="com.vaannila.service.UserServiceImpl" />
    
    <bean name="/userRegistration.htm" class="com.vaannila.web.UserController" p:userService-ref="userService" p:formView="userForm" p:successView="userSuccess" />

agent Monitoring , not just Controller Oh, but I only demonstrate how to monitor mysql , you can try to monitor Controller . All ready, just write the cases directly to mysql .


the problem is solved in two steps:
1. Make sure that AOP is properly configured and can achieve faceted functions: this section can be found in spring's official documentation: spring-framework-reference [AOP chapter]
2. How to write the intercept annotations when entering the controller method: the idea is as follows. You can intercept through the package path or through @ RequestMapping annotations. Reference: spring-framework-reference [how to declare crosscutting points]

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b32316-2b570.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b32316-2b570.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?