12-Java Configuration Flashcards

1
Q

Overrides of ApplicationContext.getBean

A
  1. getBean(Class)

2. getBean(id, Class)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to combine multiple configuration classes?

A
@Configuration
@Import({ Config1.class, Config2.class })
public class Combine {}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does Spring use Objenesis lib for?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is “tramp data”?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

List out bean scopes

A
  1. singleton
  2. prototype: A new instance is created each time the bean is referenced
  3. session:(web-aware) per session. Used in web env
  4. request:(web-aware) per request. Used in web env
  5. application:(web-aware) last as long as the ServletContext
  6. global: last as long as a global HttpSession in a Portlet application (obsoleted)
  7. websocket:(web-aware) per web-socket connection
  8. refresh scope
  9. thread scope (defined but not registered by default)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the implementation of ApplicationContext in a web app?

A

WebApplicationContext

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to create a custom scope?

A

Create a bean of type CustomScopeConfigurer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to enable the last bean to override the one with the same name?

A

spring.main.allow-bean-definition-overriding=true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What happens if defining 2 beans with the same name?

A

No exception thrown. Spring will pick the first one it found

How well did you know this?
1
Not at all
2
3
4
5
Perfectly