对于@Configuration的ProxyBeanMethods属性的疑惑

img

我理解是:如果配置类不是生成的代理对象,那就不去容器里面拿直接new一个新的,有什么错吗难道不是还可以用吗

你如果设置proxyBeanMethods = false,会出现下面的编译错误提示吧

Method annotated with @Bean is called directly in a @Configuration where proxyBeanMethods set to false. Set proxyBeanMethods to true or use dependency injection. 

这个主要是两个组件直接有依赖关系,hisUser依赖yourUser,这样你设置proxyBeanMethods = false,spring容器就无法保证获取的yourUser是同一个ioc容器的组件;而且你看编译的错误提示已经很明确了