12-Java Configuration Flashcards
Overrides of ApplicationContext.getBean
- getBean(Class)
2. getBean(id, Class)
How to combine multiple configuration classes?
@Configuration @Import({ Config1.class, Config2.class }) public class Combine {}
What does Spring use Objenesis lib for?
Prior to Spring 4.3, we cannot use constructor injection i.e. pass in dependency to the constructor, all beans need to have a default constructor. This is a CGLIB restriction
Use Objenesis to overcome this.
What is “tramp data”?
Tramp Data in this case are variables passed from one method to another until they are used.
Dependency injection is designed to avoid this in Spring Beans
List out bean scopes
- singleton
- prototype: A new instance is created each time the bean is referenced
- session:(web-aware) per session. Used in web env
- request:(web-aware) per request. Used in web env
- application:(web-aware) last as long as the ServletContext
- global: last as long as a global HttpSession in a Portlet application (obsoleted)
- websocket:(web-aware) per web-socket connection
- refresh scope
- thread scope (defined but not registered by default)
What is the implementation of ApplicationContext in a web app?
WebApplicationContext
How to create a custom scope?
Create a bean of type CustomScopeConfigurer
How to enable the last bean to override the one with the same name?
spring.main.allow-bean-definition-overriding=true
What happens if defining 2 beans with the same name?
No exception thrown. Spring will pick the first one it found