1 Star 1 Fork 156

2901384949 / Spring-Analysis

forked from huifer / Code-Analysis 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Spring-ExposeBeanNameIntroduction.md 1.13 KB
一键复制 编辑 原始数据 按行查看 历史
huifer 提交于 2020-12-11 12:43 . feat: 0.0.11

Spring ExposeBeanNameIntroduction

  • 类全路径: org.springframework.aop.interceptor.ExposeBeanNameAdvisors.ExposeBeanNameIntroduction

成员变量

  • beanName

方法分析

invoke

  • 方法签名: org.springframework.aop.interceptor.ExposeBeanNameAdvisors.ExposeBeanNameIntroduction.invoke

  • 方法作用: 设置BEAN_NAME_ATTRIBUTE属性为 beanName

完整代码

	@SuppressWarnings("serial")
	private static class ExposeBeanNameIntroduction extends DelegatingIntroductionInterceptor implements NamedBean {

		private final String beanName;

		public ExposeBeanNameIntroduction(String beanName) {
			this.beanName = beanName;
		}

		@Override
		public Object invoke(MethodInvocation mi) throws Throwable {
			if (!(mi instanceof ProxyMethodInvocation)) {
				throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
			}
			ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi;
			// 设置属性
			pmi.setUserAttribute(BEAN_NAME_ATTRIBUTE, this.beanName);
			return super.invoke(mi);
		}

		@Override
		public String getBeanName() {
			return this.beanName;
		}
	}
Java
1
https://gitee.com/cc2901384949/spring-analysis.git
git@gitee.com:cc2901384949/spring-analysis.git
cc2901384949
spring-analysis
Spring-Analysis
master

搜索帮助