Spring-笔记

1)bean的解析

关键函数位于:

org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions

/**
	 * Populate the given DocumentDefaultsDefinition instance with the default lazy-init,
	 * autowire, dependency check settings, init-method, destroy-method and merge settings.
	 */
	protected void populateDefaults(DocumentDefaultsDefinition defaults, Element root) {
		//看到这里了
		defaults.setLazyInit(root.getAttribute(DEFAULT_LAZY_INIT_ATTRIBUTE));
		defaults.setMerge(root.getAttribute(DEFAULT_MERGE_ATTRIBUTE));
		defaults.setAutowire(root.getAttribute(DEFAULT_AUTOWIRE_ATTRIBUTE));
		defaults.setDependencyCheck(root.getAttribute(DEFAULT_DEPENDENCY_CHECK_ATTRIBUTE));
		if (root.hasAttribute(DEFAULT_AUTOWIRE_CANDIDATES_ATTRIBUTE)) {
			defaults.setAutowireCandidates(root.getAttribute(DEFAULT_AUTOWIRE_CANDIDATES_ATTRIBUTE));
		}
		if (root.hasAttribute(DEFAULT_INIT_METHOD_ATTRIBUTE)) {
			defaults.setInitMethod(root.getAttribute(DEFAULT_INIT_METHOD_ATTRIBUTE));
		}
		if (root.hasAttribute(DEFAULT_DESTROY_METHOD_ATTRIBUTE)) {
			defaults.setDestroyMethod(root.getAttribute(DEFAULT_DESTROY_METHOD_ATTRIBUTE));
		}
		defaults.setSource(this.readerContext.extractSource(root));
	}

 

 

真正执行的函数是:

org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions

 

配置文件模板

<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="
	   http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.0.xsd 
       http://www.springframework.org/schema/aop     
       http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

 

2)关于AOP

配置文件模板

<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xmlns:context="http://www.springframework.org/schema/context"
	 xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.0.xsd 
       http://www.springframework.org/schema/aop     
       http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

	<!-- bean here -->
	<bean id="audience" class="aoptest.Audience" />
	<bean id="actor" class="aoptest.Actor" />

	<!-- aop configuration -->
	<aop:config>
		<aop:aspect ref="audience">
			<aop:pointcut id="logaop" expression="execution(* aoptest.Actor.action(..))" />
			<aop:around pointcut-ref="logaop" method="around" />
		</aop:aspect>
	</aop:config>

</beans>

学习过程中的一些知识点:

解析类:

main[1] print handlerOrClassName
 handlerOrClassName = "org.springframework.aop.config.AopNamespaceHandler"

 

解析execution的地方位于:

> 
Step completed: "thread=main", org.springframework.aop.config.ConfigBeanDefinitionParser.parsePointcut(), line=435 bci=9
435    		String expression = pointcutElement.getAttribute(EXPRESSION);

 

真正被触发执行的函数是:

org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs
进入是通过stop in  org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod
stop in org.springframework.aop.aspectj.AbstractAspectJAdvice.argBinding

 

转载于:https://my.oschina.net/qiangzigege/blog/738461

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值