now I am learning SpringBoot. really got confused about the annotation @Configuration(proxyBeanMethods = false)
I defined an configuration class like the following,
@Configuration(proxyBeanMethods = false)
public class BeanConfiguration {
@Bean("User")
@ConfigurationProperties(prefix = "user2")
public User getUser(){
return new User();
}
}
I thought every bean will be different, cause it doesn't work in singleton mode.
but the test code shows me a different idea.
@SpringBootApplication
public class Boot2InitializrApplication {
public static void main(String[] args) {
ConfigurableApplicationContext applicationContext = SpringApplication.run(Boot2InitializrApplication.class, args);
User user1 = (User)applicationContext.getBean(User.class);
User user2 = (User)applicationContext.getBean(User.class);
System.out.println((user1 == user2)); **//here ? always true. even if I set 'proxyBeanMethods = false' .**
BeanConfiguration bean = applicationContext.getBean(BeanConfiguration.class);
User user3 = bean.getUser();
User user4 = bean.getUser();
System.out.println(user3==user4); //here, it varies when proxyBeanMethods is set true or/false.
}
}
Why does the bean I get through applicationContext always work under singleton mode?