Spring is often counter intuitive. Of course, if you know your Spring, you should know how it behaves, but I doubt that anyone knows the entire API by heart, and somebody, who is not a Spring-trained will have a hard time with constructs like this:
@Configuration
public class SpringConfig
{
@Bean
public BeanA beanA()
{
return new BeanA();
}
}
Any Java developer should expect method beanA() to return a new instance on every call.
But in Spring things are different: The @Bean makes the method a bean definition and since Spring beans are singletons by default, you will get the same instance on every call.
Keine Kommentare:
Kommentar veröffentlichen