package com.company.projectname.module.config;
import org.springframework.beans.BeanMetadataAttribute;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.MethodOverrides;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ScannedGenericBeanDefinition;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.MethodMetadata;
import org.springframework.util.MultiValueMap;
import java.util.Set;
@Configuration
public class BeanCustomerDifinitionPostProcessor implements BeanDefinitionRegistryPostProcessor {
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
ScannedGenericBeanDefinition globalExceptionHandler = (ScannedGenericBeanDefinition)registry.getBeanDefinition("globalExceptionHandler");
globalExceptionHandler.setLazyInit(true);
globalExceptionHandler.setPrimary(false);
AnnotationMetadata metadata = globalExceptionHandler.getMetadata();
MultiValueMap<String, Object> allAnnotationAttributes = metadata.getAllAnnotationAttributes("org.springframework.core.annotation.Order");
Set<MethodMetadata> annotatedMethods = metadata.getAnnotatedMethods("order");
for(MethodMetadata methodMetadata: annotatedMethods) {
String methodName = methodMetadata.getMethodName();
System.out.println(methodName);
}
allAnnotationAttributes.set("value",1);
globalExceptionHandler.setAbstract(true);
registry.registerBeanDefinition("globalExceptionHandler", globalExceptionHandler);
}
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
}
}
最后修改于 2023-10-12 07:33:03
如果觉得我的文章对你有用,请随意赞赏
扫一扫支付

