首页 > 技术文章 > proxyBeanMethods

yanxiaoseng 2021-03-28 00:46 原文

@Configuration注解的属性proxyBeanMethods

​ 先看源码

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Configuration {
    
   
    @AliasFor(annotation = Component.class)
	String value() default "";
   
    
    boolean proxyBeanMethods() default true;
}

​ 这里新建两个类用来测试

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Human {
    private String name;
    private Pet pet;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Pet {
    private String name;
}

​ 然后新建一个配置类用来测试

@Configuration(proxyBeanMethods = true)
public class MyConfig {

    @Bean
    public Human human01() {
        return new Human("kozo", tomcat());
    }

    @Bean
    public Pet tomcat() {
        return new Pet("tomcat");
    }
}

​ 在开关类的main方法中做验证

image

​ 当proxyBeanMethods = true时

image

​ 当proxyBeanMethods = false时,(这时idea给了一个提示)

image

image

推荐阅读