springboot注解@Configuration属性proxyBeanMethods详解

proxyBeanMethods属性默认值是true,也就是说该配置类会被代理(CGLIB),在同一个配置文件中调用其它被@Bean注解标注的方法获取对象时会直接从IOC容器之中获取;

1.看下源码注解
java 复制代码
	/**
	 * Specify whether {@code @Bean} methods should get proxied in order to enforce
	 * bean lifecycle behavior, e.g. to return shared singleton bean instances even
	 * in case of direct {@code @Bean} method calls in user code. This feature
	 * requires method interception, implemented through a runtime-generated CGLIB
	 * subclass which comes with limitations such as the configuration class and
	 * its methods not being allowed to declare {@code final}.
	 * <p>The default is {@code true}, allowing for 'inter-bean references' via direct
	 * method calls within the configuration class as well as for external calls to
	 * this configuration's {@code @Bean} methods, e.g. from another configuration class.
	 * If this is not needed since each of this particular configuration's {@code @Bean}
	 * methods is self-contained and designed as a plain factory method for container use,
	 * switch this flag to {@code false} in order to avoid CGLIB subclass processing.
	 * <p>Turning off bean method interception effectively processes {@code @Bean}
	 * methods individually like when declared on non-{@code @Configuration} classes,
	 * a.k.a. "@Bean Lite Mode" (see {@link Bean @Bean's javadoc}). It is therefore
	 * behaviorally equivalent to removing the {@code @Configuration} stereotype.
	 * @since 5.2
	 */
	boolean proxyBeanMethods() default true;
1234567891011121314151617181920

注解的意思是proxyBeanMethods配置类是用来指定@Bean注解标注的方法是否使用代理,默认是true使用代理,直接从IOC容器之中取得对象;如果设置为false,也就是不使用注解,每次调用@Bean标注的方法获取到的对象和IOC容器中的都不一样,是一个新的对象,所以我们可以将此属性设置为false来提高性能;

GitHub地址:https://github.com/mingyang66/spring-parent/tree/master/doc/base

相关推荐
枫叶落雨22220 分钟前
06kafka及异步通知文章上下架
java
Lizhihao_2 小时前
JAVA-Thread类实现多线程
java·开发语言
勇敢牛牛_2 小时前
【Rust基础】Rust后端开发常用库
开发语言·后端·rust
编程毕设2 小时前
【含文档+PPT+源码】基于微信小程序的驾考在线学习与测试系统的设计与实现
java·学习·eclipse·tomcat
奔跑的废柴3 小时前
LeetCode 112. 路径总和 II java题解
java·算法·leetcode·二叉树
独孤求败Ace3 小时前
第54天:Web攻防-SQL注入&数据类型&参数格式&JSON&XML&编码加密&符号闭合&复盘报告
xml·java·sql
紫乾20144 小时前
idea cpu干到100%的解决方法?
java·ide·intellij-idea
路在脚下@4 小时前
使用RabbitMQ实现流量削峰填谷
spring boot·rabbitmq
小安同学iter5 小时前
SpringMVC(三)响应处理
java·spring
努力小贼5 小时前
SpringBoot——Maven篇
java·spring boot·maven