Java Configuration Flashcards

1
Q

What does @Configuration do?

A

It tells spring it has bean-definitions (methods) in the class.

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

What does @Bean mean

A

The @Bean annotation is used to indicate that a method instantiates, configures, and initializes a new object to be managed by the Spring IoC container

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

True or false? The bean name is the same as the @Bean methodName()

A

True

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

How can you access a Bean?

A

get the application context and then .getBean(<Methodname>) and cast it to right reference type.</Methodname>

e.g.

ApplicationContext context = SpringApplication.run(<className>)</className>

<AClassName> className = (<AclassName>) context.getBean(<method/beanName>);
</AclassName></AClassName>

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

True/False - Spring configuration is completely decoupled from business logic?

A

True

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

In what order does the Application Context

A
  1. dataSource (the database)
  2. the repository
  3. the service
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

In What environment can you create the spring context?

A

Basically in any context
e.g.

  • Standalone application
  • Web application
  • Junit test
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How can you create the application context from multiple configurations?

A

When a configuration class become to big you can split it up. You can again combine them by using @Import.

e.g.

@Configuration
@Import({configOne.class, configTwo.class})
public class InfraConfiguaration {
….
}

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

What is the default scope of a bean?

A

A singleton (design pattern)

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

How can you change the scope of the bean?

A

by adding @Scope to the bean

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

What are the 4 most used bean scopes?

A
  • Singleton: a single instance is used
  • prototype: a new instance is created each time a bean is referenced
  • session : a new instance is create once per user session (web app only)
  • Request: a new instance is created once per request (webapp only)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly