springboot扫描⾃定义类注解、⽅法注解
import lombok.Data;
import t.ApplicationListener;
calmdownimport t.event.ContextRefreshedEvent;
什么是ipcimport annotation.AnnotationUtils;
import org.springframework.stereotype.Component;
import flect.InvocationTargetException;
import flect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/
**
* @ClassName: CustomAnnotationDemo
* @Description: ⾃定义类注解、⽅法注解demo
* @Author: RuiXin Yu
* @Date: 2019/3/21 10:35
*/
@Component
public class CustomAnnotationDemo implements ApplicationListener<ContextRefreshedEvent>{
public static List<Invoker> invokerList =new ArrayList<>();
@Override
public void onApplicationEvent(ContextRefreshedEvent event){
/
/ 根容器为Spring容器
ApplicationContext().getParent()==null){
thin的比较级Map<String,Object> beans = ApplicationContext().getBeansWithAnnotation(OnsConsumer.class);
for(Object bean : beans.values()){
australiaOnsConsumer ca = Class().getAnnotation(OnsConsumer.class);
System.out.Class().getName()+"==="+ca.value());
Method[] methods = Class().getMethods();
for(Method declaredMethod : methods){
System.out.Name());
ConsumerMapping ma = AnnotationUtils.findAnnotation(declaredMethod, ConsumerMapping.class);
if(ma != null){
the living proof
invokerList.add(new Invoker(declaredMethod,ma.value(),bean));猜测
System.out.Class().getName()+"==="+ca.value()+"==="+ma.value());
}
}
Method[] declaredMethods = Class().getDeclaredMethods();
for(Method declaredMethod : declaredMethods){
System.out.Name());
ConsumerMapping ma = Annotation(ConsumerMapping.class);
苏州纹绣if(ma != null){
System.out.Class().getName()+"==="+ca.value()+"==="+ma.value());
}
jonas salk}
}
}
invoke();
}
private void invoke(){
for(Invoker invoker : invokerList){
try{
}catch(IllegalAccessException e){
e.printStackTrace();
}catch(InvocationTargetException e){
e.printStackTrace();
}
}
}
@Data
class Invoker{
private Method method;
private String tag;
private Object bean;
半半路路
public Invoker(Method method, String tag, Object bean){
this.tag = tag;
this.bean = bean;
}
}
}
>driver是什么意思