zoukankan      html  css  js  c++  java
  • spring注解

    AnnotationConfigApplicationContext

    Java配置方式

    @Test(expected = BeanCreationException.class)
    public void testFbkMethod() {
    	new AnnotationConfigApplicationContext(TestConfig1.class);
    }
    

    bean的注册

    public class SimpleBeanDefinitionRegistry extends SimpleAliasRegistry implements BeanDefinitionRegistry {
    
    	/** Map of bean definition objects, keyed by bean name. */
    	private final Map<String, BeanDefinition> beanDefinitionMap = new ConcurrentHashMap<>(64);
    
    	@Override
    	public void registerBeanDefinition(String beanName, BeanDefinition beanDefinition)
    			throws BeanDefinitionStoreException {
    
    		Assert.hasText(beanName, "'beanName' must not be empty");
    		Assert.notNull(beanDefinition, "BeanDefinition must not be null");
    		this.beanDefinitionMap.put(beanName, beanDefinition);
    	}
    }
    

    spring多播器,事件监听

    AnnotationConfigApplicationContext.class

    public AnnotationConfigApplicationContext(Class<?>... annotatedClasses) {
    	this();
    	register(annotatedClasses);
    	refresh();
    }
    

    AbstractApplicationContext.refresh()

    注册事件广播器

    // Initialize event multicaster for this context.
    initApplicationEventMulticaster();
    

    ApplicationEventMulticaster.multicastEvent(final ApplicationEvent event, @Nullable ResolvableType eventType)

    通知观察者,进行事件播放

    Interface to be implemented by objects that can manage a number of
    {@link ApplicationListener} objects, and publish events to them.

    @Override
    public void multicastEvent(final ApplicationEvent event, @Nullable ResolvableType eventType) {
    	ResolvableType type = (eventType != null ? eventType : resolveDefaultEventType(event));
    	Executor executor = getTaskExecutor();
    	for (ApplicationListener<?> listener : getApplicationListeners(event, type)) {
    		if (executor != null) {
    			executor.execute(() -> invokeListener(listener, event));
    		}
    		else {
    			invokeListener(listener, event);
    		}
    	}
    }
    
  • 相关阅读:
    解决点击状态栏时ScrollView自动滚动到初始位置失效办法
    如何设计用户、角色、权限表
    Subject的功能
    shiro授权的源码分析
    shiro之认证源码分析
    shiro配置
    JSONArray转JSONObject
    parameterType
    MyBatis:Parameter Maps collection does not contain value for 的问题解决
    mybatis报ORA-00911: 无效字符
  • 原文地址:https://www.cnblogs.com/zhuxiang1633/p/15074258.html
Copyright © 2011-2022 走看看