spring in action 2.0读书笔记(一)

Spring containers: BeanFactory 和 application context的区别
ApplicationContext offers much more:
■ Application contexts provide a means for resolving text messages, including support for internationalization (I18N) of those messages.
■ Application contexts provide a generic way to load file resources, such as images.
■ Application contexts can publish events to beans that are registered as listeners.
A bean factory lazily loads all beans, deferring bean creation until the getBean() method is called. An application context is a bit smarter and preloads all singleton beans upon context startup.
constructor-injection vs setter injection
Constructor injection enforces a strong dependency contract. In short, a bean cannot be instantiated without being given all of its dependencies.
Because all of the bean’s dependencies are set through its constructor, there’s no need for superfluous setter methods. This helps keep the lines of code at a minimum.
By only allowing properties to be set through the constructor, you are, effectively, making those properties immutable, preventing accidental change in the course of application flow.

你可能感兴趣的:(spring,bean,读书)