com.github.lhnonline.boot.common.config.HttpRequestLogAopReg Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of weboot-common Show documentation
Show all versions of weboot-common Show documentation
用于SpringBoot项目 | 接口返回数据包装,http状态码aop, http请求日志统一打印 | 使用了fastjson,和 mybatis-plus-extension
The newest version!
package com.github.lhnonline.boot.common.config;
import com.github.lhnonline.boot.common.aop.HttpRequestLogAop;
import com.github.lhnonline.boot.common.log.DefaultLogWriter;
import com.github.lhnonline.boot.common.log.ILogWriter;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.util.StringUtils;
/**
* author luohaonan
* date 2020-11-11
* email [email protected]
* description
*/
public class HttpRequestLogAopReg implements ImportBeanDefinitionRegistrar, BeanFactoryAware {
private BeanFactory beanFactory;
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
Class beanClass = HttpRequestLogAop.class;
RootBeanDefinition beanDefinition = new RootBeanDefinition(beanClass);
String beanName = StringUtils.uncapitalize(beanClass.getSimpleName());
registry.registerBeanDefinition(beanName, beanDefinition);
try {
beanFactory.getBean(ILogWriter.class);
} catch (BeansException e) {
beanClass = DefaultLogWriter.class;
beanDefinition = new RootBeanDefinition(beanClass);
beanName = StringUtils.uncapitalize(beanClass.getSimpleName());
registry.registerBeanDefinition(beanName, beanDefinition);
}
}
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanFactory = beanFactory;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy