
package cn.orionsec.ops.config;

import cn.orionsec.ops.interceptor.LogPrintInterceptor;
import org.springframework.aop.aspectj.AspectJExpressionPointcutAdvisor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Configuration
@ConditionalOnBean(LogPrintInterceptor.class)
public class LogPrintConfig {

    @Value("${log.interceptor.expression:}")
    private String logInterceptorExpression;

    @Resource
    private LogPrintInterceptor logPrintInterceptor;

    @Bean
    @ConditionalOnProperty(name = "log.interceptor.expression")
    public AspectJExpressionPointcutAdvisor logAdvisor() {
        AspectJExpressionPointcutAdvisor advisor = new AspectJExpressionPointcutAdvisor();
        advisor.setExpression(logInterceptorExpression);
        advisor.setAdvice(logPrintInterceptor);
        return advisor;
    }

}
