Week 2 Review — Configuration, Profiles, Scopes, and Bean Lifecycle
Goal
This review checks if I really understand Week 2.
Week 2 topics:
- Java configuration
@Configuration@Bean- Full vs lite configuration mode
proxyBeanMethods- External configuration
application.propertiesapplication.yml@Value@ConfigurationProperties- Profiles
@Profile- Bean scopes
- Singleton vs prototype
- Request and session scope
- Scoped proxy
- Bean lifecycle
@PostConstruct@PreDestroyBeanPostProcessor
1. Week 2 Big Picture
Week 1 answered:
How does Spring create and connect objects?
Week 2 answers:
How does Spring configure, activate, scope, initialize, and destroy those objects?
Spring does not only create beans.
Spring also controls:
how beans are configured
which beans are active
how long beans live
when beans are initialized
when beans are destroyed
whether beans are proxied
2. Core Memory Sentences
Memorize these:
@Configuration marks a class as a source of bean definitions.
@Bean marks a method whose return value becomes a Spring bean.
@Component is used on classes.
@Bean is used on methods.
Use @Bean for third-party classes or custom creation logic.
Full @Configuration classes are proxied to preserve singleton behavior.
@Configuration(proxyBeanMethods = false) disables @Bean method proxying.
Prefer @Bean method parameters over calling another @Bean method directly.
External configuration keeps environment-specific values outside Java code.
application.properties is flat key-value configuration.
application.yml is hierarchical configuration.
@Value injects one configuration value.
@ConfigurationProperties binds grouped configuration to a Java object.
@ConfigurationProperties classes must be registered as beans.
Profiles control which configuration and beans are active.
application-dev.yml loads only when the dev profile is active.
@Profile("dev") means the bean is active only in the dev profile.
@Profile("!prod") means the bean is active when prod is not active.
The default bean scope is singleton.
Spring singleton means one bean instance per Spring container.
Prototype scope creates a new bean each time it is requested.
A prototype injected into a singleton is created once when the singleton is created.
ObjectProvider can help a singleton get fresh prototype instances.
Request scope means one bean per HTTP request.
Session scope means one bean per HTTP session.
Scoped proxy lets a singleton depend on a request-scoped or session-scoped bean.
@PostConstruct runs after dependency injection.
@PreDestroy runs before bean destruction.
BeanPostProcessor can modify or wrap beans.
AOP proxies are often created by BeanPostProcessors.
3. Concept Map
Spring Configuration
│
├── Java Configuration
│ ├── @Configuration
│ ├── @Bean
│ ├── full configuration mode
│ ├── lite configuration mode
│ └── proxyBeanMethods
│
├── External Configuration
│ ├── application.properties
│ ├── application.yml
│ ├── @Value
│ ├── @ConfigurationProperties
│ ├── environment variables
│ └── command-line arguments
│
├── Profiles
│ ├── dev
│ ├── test
│ ├── prod
│ ├── @Profile
│ ├── application-dev.yml
│ └── @ActiveProfiles
│
├── Bean Scopes
│ ├── singleton
│ ├── prototype
│ ├── request
│ ├── session
│ └── scoped proxy
│
└── Bean Lifecycle
├── instantiate
├── inject dependencies
├── aware callbacks
├── BeanPostProcessor before init
├── @PostConstruct
├── BeanPostProcessor after init
├── bean ready
└── @PreDestroy
4. Most Important Exam Traps
Trap 1 — @Bean Method Name
@Bean
public Clock clock() {
return Clock.systemUTC();
}
Default bean name:
clock
The method name becomes the bean name.
Trap 2 — @Component vs @Bean
Wrong:
@Component and @Bean are the same.
Correct:
@Component is used on a class.
@Bean is used on a method.
Trap 3 — Full @Configuration
@Configuration
public class AppConfig {
@Bean
public A a() {
return new A();
}
@Bean
public B b() {
return new B(a());
}
}
In full configuration mode, Spring proxies the configuration class.
The call to a() inside b() returns the managed singleton bean.
Trap 4 — proxyBeanMethods = false
@Configuration(proxyBeanMethods = false)
public class AppConfig {
@Bean
public A a() {
return new A();
}
@Bean
public B b() {
return new B(a());
}
}
Here, a() inside b() is a normal Java method call.
It may create a separate A object.
Better:
@Bean
public B b(A a) {
return new B(a);
}
Trap 5 — @ConfigurationProperties Registration
This is not enough alone:
@ConfigurationProperties(prefix = "jwt")
public record JwtProperties(String secret) {
}
The class must also be registered with Spring.
Use one of these:
@ConfigurationPropertiesScan
or:
@EnableConfigurationProperties(JwtProperties.class)
or:
@Component
@ConfigurationProperties(prefix = "jwt")
Trap 6 — @Value Only Works in Spring Beans
This works:
@Component
public class AppInfo {
public AppInfo(@Value("${app.name}") String appName) {
}
}
This does not work automatically:
AppInfo appInfo = new AppInfo();
because the object is not managed by Spring.
Trap 7 — Profile Files Do Not Load Automatically
This file:
application-prod.yml
loads only when:
prod profile is active
It does not load only because the file exists.
Trap 8 — @Profile("default") vs @Profile("!prod")
@Profile("default")
means:
active only when no explicit profile is active
@Profile("!prod")
means:
active whenever prod is not active
Trap 9 — Prototype in Singleton
@Service
public class JobService {
private final JobContext jobContext;
public JobService(JobContext jobContext) {
this.jobContext = jobContext;
}
}
If JobContext is prototype and JobService is singleton, Spring injects one prototype instance when the singleton is created.
It does not create a new prototype on every method call.
Trap 10 — Singleton Is Not Automatically Thread-Safe
Spring singleton means:
one bean per Spring container
It does not mean:
thread-safe
Do not store request-specific mutable state in singleton fields.
Trap 11 — Prototype Destruction
Spring creates and initializes prototype beans.
But Spring does not automatically call destroy callbacks for prototype beans when the context closes.
Trap 12 — @PostConstruct
@PostConstruct runs:
after dependency injection
not before.
Trap 13 — @PreDestroy
@PreDestroy runs:
before bean destruction
usually when the application context closes for singleton beans.
Trap 14 — BeanPostProcessor
A BeanPostProcessor can return a proxy instead of the original bean.
This is important for:
AOP
@Transactional
security
caching
Trap 15 — Self-Invocation in @PostConstruct
Bad:
@PostConstruct
public void init() {
transactionalMethod();
}
@Transactional
public void transactionalMethod() {
}
This is self-invocation.
The call may bypass the Spring proxy.
@Transactional may not work as expected.
Practice Questions and Answers
Question 1
What does @Configuration do?
Answer:
@Configuration marks a class as a source of Spring bean definitions. Spring processes the class and registers beans from its @Bean methods.
Question 2
What does @Bean do?
Answer:
@Bean marks a method whose return value should be registered as a Spring bean.
Question 3
What is the default bean name for a @Bean method?
Answer:
By default, the method name becomes the bean name.
Question 4
When should I use @Bean instead of @Component?
Answer:
Use @Bean for third-party classes, classes I cannot modify, custom object creation logic, objects needing property values, factory methods, or multiple beans of the same type.
Question 5
Why are full @Configuration classes proxied?
Answer:
Full @Configuration classes are proxied so Spring can intercept calls to @Bean methods and return managed singleton beans instead of creating new objects.
Question 6
What does @Configuration(proxyBeanMethods = false) mean?
Answer:
@Configuration(proxyBeanMethods = false) disables proxying of @Bean methods. Direct calls between @Bean methods are normal Java method calls.
Question 7
What is external configuration?
Answer:
External configuration means storing environment-specific values outside Java code, for example in application.yml, environment variables, command-line arguments, or profile-specific files.
Question 8
What is the difference between @Value and @ConfigurationProperties?
Answer:
@Value injects one configuration value. @ConfigurationProperties binds a group of related configuration properties to a Java object.
Question 9
How can I register a @ConfigurationProperties class?
Answer:
Use @ConfigurationPropertiesScan, @EnableConfigurationProperties, or add @Component together with @ConfigurationProperties.
Question 10
What is relaxed binding?
Answer:
Relaxed binding means Spring Boot can bind different property naming styles, such as base-url, baseUrl, base_url, and BASE_URL, to the same Java property.
Question 11
What is a Spring profile?
Answer:
A Spring profile is a named environment mode that controls which configuration and beans are active.
Question 12
When does application-dev.yml load?
Answer:
application-dev.yml loads when the dev profile is active.
Question 13
What does @Profile("!prod") mean?
Answer:
@Profile("!prod") means the bean is active when the prod profile is not active.
Question 14
What is the default bean scope?
Answer:
The default bean scope is singleton.
Question 15
What does singleton mean in Spring?
Answer:
Singleton means one bean instance per Spring IoC container.
Question 16
What does prototype scope mean?
Answer:
Prototype scope means Spring creates a new bean instance every time the bean is requested from the container.
Question 17
What happens when a prototype bean is injected into a singleton bean?
Answer:
The prototype bean is created once when the singleton bean is created. The singleton keeps that same prototype instance.
Question 18
What is request scope?
Answer:
Request scope means one bean instance per HTTP request.
Question 19
What is a scoped proxy?
Answer:
A scoped proxy is a proxy object that lets a long-lived bean, such as a singleton, depend on a short-lived scoped bean, such as a request-scoped or session-scoped bean.
Question 20
When does @PostConstruct run?
Answer:
@PostConstruct runs after the bean has been created and dependencies have been injected.
Question 21
When does @PreDestroy run?
Answer:
@PreDestroy runs before the bean is destroyed, usually when the application context closes for singleton beans.
Question 22
What is BeanPostProcessor?
Answer:
BeanPostProcessor is a Spring extension point that can inspect, modify, or wrap beans before and after initialization.
Question 23
How are AOP proxies related to BeanPostProcessor?
Answer:
AOP proxies are often created by BeanPostProcessors. A post-processor can wrap a bean with a proxy that adds behavior such as transactions, security, caching, or logging.
Question 24
Does Spring automatically destroy prototype beans?
Answer:
No. Spring creates and initializes prototype beans, but it does not automatically manage their destruction.
Question 25
Why should singleton services usually be stateless?
Answer:
Singleton services are shared across requests and threads. If they store request-specific mutable state in fields, different requests can overwrite each other’s data and cause race conditions.
7. Mini Mock Exam — Week 2
Instructions
Try to answer without checking notes.
Recommended time:
35 minutes
Passing score:
80%
There are 35 questions.
Question 1
What does @Configuration mark?
A. A REST endpoint B. A class that contains Spring bean definitions C. A database entity D. A test class only
My answer:
Question 2
What does @Bean do?
A. Marks a class as a database table B. Marks a method whose return value becomes a Spring bean C. Enables CORS D. Starts embedded Tomcat
My answer:
Question 3
What is the default bean name here?
@Bean
public Clock clock() {
return Clock.systemUTC();
}
A. Clock
B. clock
C. systemUTC
D. timeClock
My answer:
Question 4
When is @Bean usually a good choice?
A. For third-party classes or custom object creation B. Only for entities C. Only for controllers D. Never
My answer:
Question 5
Which statement is correct?
A. @Component is used on methods, @Bean is used on classes
B. @Component is used on classes, @Bean is used on methods
C. Both are used only on fields
D. Both are only for tests
My answer:
Question 6
Why does Spring proxy full @Configuration classes?
A. To make controllers faster
B. To intercept @Bean method calls and preserve singleton behavior
C. To convert JSON
D. To enable SQL logging
My answer:
Question 7
What does @Configuration(proxyBeanMethods = false) do?
A. Disables all beans
B. Disables proxying of @Bean methods
C. Enables request scope
D. Enables profiles
My answer:
Question 8
Which style is usually better?
A.
@Bean
public B b() {
return new B(a());
}
B.
@Bean
public B b(A a) {
return new B(a);
}
My answer:
Question 9
What is external configuration?
A. Hardcoding values in Java classes B. Storing environment-specific values outside Java code C. Creating entities manually D. Writing SQL in controllers
My answer:
Question 10
Which file is hierarchical and indentation-sensitive?
A. application.yml
B. application.properties
C. pom.xml
D. README.md
My answer:
Question 11
What is @Value best for?
A. Injecting one simple configuration value B. Binding a large group of properties C. Creating REST endpoints D. Creating database tables
My answer:
Question 12
What happens if this property is missing and no default is provided?
@Value("${app.name}")
private String appName;
A. Spring injects null silently B. Spring usually fails to start C. Spring ignores the field D. Spring creates a random value
My answer:
Question 13
What is @ConfigurationProperties best for?
A. One simple value only B. Grouped, structured, type-safe configuration C. Controller mapping D. Bean destruction only
My answer:
Question 14
Does @ConfigurationProperties automatically create a bean by itself in every case?
A. Yes B. No, the properties class must also be registered C. Only in XML apps D. Only in tests
My answer:
Question 15
Which one can register @ConfigurationProperties classes?
A. @ConfigurationPropertiesScan
B. @PathVariable
C. @RequestBody
D. @ControllerAdvice
My answer:
Question 16
What is relaxed binding?
A. Spring ignores missing beans B. Different property name styles can bind to the same Java property C. Spring disables validation D. Spring removes profiles
My answer:
Question 17
What can EXTERNAL_API_BASE_URL bind to?
A. external-api.base-url
B. external.api.base.url.only only
C. ExternalApiBaseUrl class only
D. Nothing
My answer:
Question 18
What is a Spring profile?
A. A Git profile B. A named environment mode controlling active config and beans C. A database table D. A Java package
My answer:
Question 19
When does application-prod.yml load?
A. Always
B. Only when the prod profile is active
C. Only when the app fails
D. Only in tests
My answer:
Question 20
How can I activate the prod profile from command line?
A. --spring.profiles.active=prod
B. --spring.bean.scope=prod
C. --java.profile=prod
D. --profile.database=prod
My answer:
Question 21
What does @Profile("dev") mean?
A. Bean is active only when dev profile is active
B. Bean is active only in production
C. Bean is never active
D. Bean is a controller
My answer:
Question 22
What does @Profile("!prod") mean?
A. Active only when prod is active B. Active when prod is not active C. Active only when no profile exists D. Invalid expression
My answer:
Question 23
What is the default profile?
A. A profile active when no other profile is explicitly active
B. Always dev
C. Always prod
D. A security role
My answer:
Question 24
What is the default Spring bean scope?
A. prototype B. singleton C. request D. session
My answer:
Question 25
What does Spring singleton mean?
A. One instance per JVM always B. One bean instance per Spring container C. One instance per HTTP request D. One instance per database row
My answer:
Question 26
Are Spring singleton beans automatically thread-safe?
A. Yes B. No C. Only repositories D. Only controllers
My answer:
Question 27
What does prototype scope mean?
A. One bean per application B. New bean instance every time requested from the container C. One bean per HTTP session D. One bean per profile
My answer:
Question 28
What happens when a prototype bean is injected into a singleton?
A. A new prototype is created on every singleton method call B. One prototype is injected when the singleton is created C. Spring refuses all prototype beans D. Prototype becomes request-scoped
My answer:
Question 29
What can help a singleton get a fresh prototype instance?
A. ObjectProvider<T>
B. @PathVariable
C. @RestController
D. @Entity
My answer:
Question 30
What does request scope mean?
A. One bean per HTTP request B. One bean per JVM C. One bean per database query D. One bean per application profile
My answer:
Question 31
What does session scope mean?
A. One bean per HTTP session B. One bean per method call C. One bean per controller D. One bean per Maven module
My answer:
Question 32
Why is a scoped proxy useful?
A. It allows a singleton to depend on a request/session-scoped bean B. It creates database indexes C. It disables dependency injection D. It converts properties to YAML
My answer:
Question 33
When does @PostConstruct run?
A. Before object construction B. After dependency injection C. Only after application shutdown D. Only before tests
My answer:
Question 34
When does @PreDestroy run?
A. Before bean destruction B. Before dependency injection C. Before object construction D. Before component scanning
My answer:
Question 35
What can BeanPostProcessor do?
A. Modify or wrap beans before and after initialization B. Only create database tables C. Only read YAML files D. Only activate profiles
My answer:
8. Mini Mock Exam Answers
Answer Key
1. B
2. B
3. B
4. A
5. B
6. B
7. B
8. B
9. B
10. A
11. A
12. B
13. B
14. B
15. A
16. B
17. A
18. B
19. B
20. A
21. A
22. B
23. A
24. B
25. B
26. B
27. B
28. B
29. A
30. A
31. A
32. A
33. B
34. A
35. A
9. Score
Total questions: 35
Correct answers:
Wrong answers:
Score:
Score calculation:
correct answers / 35 * 100
Example:
28 / 35 * 100 = 80%
10. Mistake Review Template
For every wrong answer, write this:
## Mistake
Question number:
My wrong answer:
Correct answer:
Why I was wrong:
Correct concept:
Memory sentence:
Example:
## Mistake
Question number: 28
My wrong answer: A
Correct answer: B
Why I was wrong:
I thought prototype scope creates a new object on every method call.
Correct concept:
A prototype bean injected into a singleton is created once when the singleton is created.
Memory sentence:
Prototype means new when requested from the container, not new on every method call.
11. Real Scenario Questions
These are more practical and interview-like.
Scenario 1 — @Bean Direct Call
Code:
@Configuration(proxyBeanMethods = false)
public class AppConfig {
@Bean
public A a() {
return new A();
}
@Bean
public B b() {
return new B(a());
}
}
Question:
What is the problem?
My answer:
Model Answer
Because proxyBeanMethods = false, Spring does not intercept the direct call to a() inside b(). That call behaves like a normal Java method call and may create a separate A object instead of using the managed Spring bean. Better style is:
@Bean
public B b(A a) {
return new B(a);
}
Scenario 2 — Missing Properties Bean
Code:
@ConfigurationProperties(prefix = "jwt")
public record JwtProperties(
String secret,
long expirationMinutes
) {
}
@Service
public class JwtService {
public JwtService(JwtProperties jwtProperties) {
}
}
Error:
No qualifying bean of type JwtProperties available
Question:
What is probably missing?
My answer:
Model Answer
The JwtProperties class is not registered as a Spring bean. Possible fixes are:
@ConfigurationPropertiesScan
or:
@EnableConfigurationProperties(JwtProperties.class)
or:
@Component
@ConfigurationProperties(prefix = "jwt")
Scenario 3 — Profile File Not Loading
File exists:
application-prod.yml
But production values are not loaded.
Question:
What is the likely reason?
My answer:
Model Answer
The prod profile is probably not active. application-prod.yml loads only when the prod profile is active.
Activate it with:
java -jar app.jar --spring.profiles.active=prod
or:
SPRING_PROFILES_ACTIVE=prod java -jar app.jar
Scenario 4 — Prototype in Singleton
Code:
@Component
@Scope("prototype")
public class ImportContext {
}
@Service
public class ImportService {
private final ImportContext importContext;
public ImportService(ImportContext importContext) {
this.importContext = importContext;
}
}
Question:
Does ImportService get a new ImportContext for each import?
My answer:
Model Answer
No. ImportService is singleton by default. Spring creates it once and injects one prototype ImportContext at creation time. The same ImportContext stays inside the singleton. To get a fresh instance, use ObjectProvider<ImportContext>.
Scenario 5 — Request State in Singleton
Code:
@Service
public class UserService {
private Long currentUserId;
public void process(Long userId) {
this.currentUserId = userId;
}
}
Question:
What is wrong?
My answer:
Model Answer
UserService is singleton by default and shared across requests. currentUserId is request-specific mutable state. Multiple requests can overwrite it and cause wrong behavior. Use method parameters, local variables, or request-scoped context instead.
Scenario 6 — @PostConstruct and Transaction
Code:
@Service
public class StartupService {
@PostConstruct
public void init() {
runInTransaction();
}
@Transactional
public void runInTransaction() {
// database work
}
}
Question:
Why is this dangerous?
My answer:
Model Answer
init() calls runInTransaction() inside the same class. This is self-invocation and may bypass the Spring proxy. Since @Transactional is proxy-based, the transaction may not be applied as expected. Better options are moving the transactional method to another bean or using ApplicationRunner.
12. Final Oral Exam — Week 2
Try to answer these out loud.
Question 1
Explain @Configuration and @Bean.
Question 2
Explain why full @Configuration classes are proxied.
Question 3
Explain @Value vs @ConfigurationProperties.
Question 4
Explain how Spring profiles work.
Question 5
Explain singleton scope.
Question 6
Explain prototype scope.
Question 7
Explain what happens when prototype is injected into singleton.
Question 8
Explain request scope and scoped proxy.
Question 9
Explain the bean lifecycle.
Question 10
Explain BeanPostProcessor and why it matters.
13. Good Oral Answers
Oral Answer 1 — @Configuration and @Bean
@Configuration marks a class as a source of Spring bean definitions. Inside that class, methods annotated with @Bean return objects that become Spring-managed beans. The method name becomes the default bean name. This is useful when I need to create third-party objects or objects with custom construction logic.
Oral Answer 2 — Why @Configuration Is Proxied
Full @Configuration classes are proxied so Spring can intercept calls to @Bean methods. This preserves singleton behavior when one @Bean method calls another. Without proxying, calling a @Bean method directly would behave like a normal Java method call and could create a new object instead of returning the managed bean.
Oral Answer 3 — @Value vs @ConfigurationProperties
@Value is used to inject one simple configuration value. @ConfigurationProperties is used to bind a group of related properties to a Java object. @ConfigurationProperties is better for structured, type-safe, validated configuration, especially when the config has nested values, lists, maps, or many related fields.
Oral Answer 4 — Profiles
Spring profiles allow different beans and configuration to be active in different environments, such as dev, test, and prod. If the dev profile is active, Spring loads application-dev.yml and creates beans annotated with @Profile("dev"). Profiles can be activated with command-line arguments, environment variables, IDE config, or @ActiveProfiles in tests.
Oral Answer 5 — Singleton Scope
Singleton is the default Spring bean scope. It means Spring creates one bean instance per Spring container and reuses it wherever needed. Services and repositories are usually singleton. Singleton does not mean thread-safe, so singleton beans should usually be stateless and should not store request-specific mutable state in fields.
Oral Answer 6 — Prototype Scope
Prototype scope means Spring creates a new bean instance every time the bean is requested from the container. It can be useful for short-lived, stateful helper objects. Spring creates and initializes prototype beans, but it does not automatically manage their destruction lifecycle.
Oral Answer 7 — Prototype into Singleton
If a prototype bean is injected directly into a singleton bean, Spring creates one prototype instance when the singleton is created. The singleton keeps that same instance. It does not get a new prototype on every method call. To get fresh prototype instances, use ObjectProvider, Provider, lookup method injection, or another lookup mechanism.
Oral Answer 8 — Request Scope and Scoped Proxy
Request scope means one bean instance per HTTP request. If a singleton service depends on a request-scoped bean, Spring can inject a scoped proxy. The singleton keeps the proxy, and the proxy delegates to the real request-scoped bean for the current request. This allows long-lived beans to depend on short-lived scoped beans safely.
Oral Answer 9 — Bean Lifecycle
The bean lifecycle is the process Spring follows to create, configure, initialize, use, and destroy beans. Spring reads the bean definition, instantiates the bean, injects dependencies, runs aware callbacks, applies BeanPostProcessors, runs initialization callbacks like @PostConstruct, and then the bean is ready. When the context closes, Spring runs destruction callbacks like @PreDestroy for singleton beans.
Oral Answer 10 — BeanPostProcessor
A BeanPostProcessor is a Spring extension point that can inspect, modify, or wrap beans before and after initialization. It is important because many Spring features use post-processors internally. AOP proxies, including transaction or security proxies, are often created by BeanPostProcessors.
14. Week 2 Final Readiness Checklist
Before moving to Week 3, I should be able to check all of these:
[ ] I can explain @Configuration.
[ ] I can explain @Bean.
[ ] I know the default @Bean name.
[ ] I can compare @Component and @Bean.
[ ] I know when to use @Bean.
[ ] I can explain full configuration mode.
[ ] I can explain lite configuration mode.
[ ] I can explain proxyBeanMethods.
[ ] I know why method-parameter injection is better than direct @Bean calls.
[ ] I can explain external configuration.
[ ] I can compare application.properties and application.yml.
[ ] I can explain @Value.
[ ] I can explain @ConfigurationProperties.
[ ] I know how to register @ConfigurationProperties classes.
[ ] I can explain relaxed binding.
[ ] I know why secrets should not be committed.
[ ] I can explain Spring profiles.
[ ] I know when application-dev.yml loads.
[ ] I can explain @Profile.
[ ] I can explain @Profile("!prod").
[ ] I can explain default profile.
[ ] I can explain singleton scope.
[ ] I can explain prototype scope.
[ ] I can explain request scope.
[ ] I can explain session scope.
[ ] I know what happens when prototype is injected into singleton.
[ ] I can explain ObjectProvider.
[ ] I can explain scoped proxy.
[ ] I know singleton beans should usually be stateless.
[ ] I can explain @PostConstruct.
[ ] I can explain @PreDestroy.
[ ] I can explain BeanPostProcessor.
[ ] I know how BeanPostProcessor relates to AOP proxies.
[ ] I know Spring does not automatically destroy prototype beans.
15. Weak Topics to Review Before Week 3
Write weak topics here:
## My Weak Topics
1.
2.
3.
4.
5.
For each weak topic:
## Weak Topic
Topic:
Why it is confusing:
Correct explanation:
Code example:
Memory sentence:
16. Week 2 Final Summary
Week 2 taught me that Spring beans are not only created and injected.
They are also:
configured
activated by profiles
scoped
initialized
post-processed
possibly proxied
destroyed
The most important ideas:
@Configuration and @Bean define beans using Java code.
External configuration keeps environment values outside code.
@ConfigurationProperties is best for grouped config.
Profiles activate environment-specific beans and files.
Singleton is the default scope.
Prototype creates new beans only when requested from the container.
Request and session scopes are web scopes.
@PostConstruct and @PreDestroy are lifecycle callbacks.
BeanPostProcessor can wrap beans with proxies.
If I understand Week 2 well, I am ready for Week 3:
Spring Boot and Auto-Configuration