Spring Framework· 35 min

Spring Beans, Configuration, and AOP

Learn bean scopes, lifecycle, profiles, configuration classes, events, interceptors, and AOP trade-offs.

Java interview lesson
Question 17 · Not reviewed

Spring · container

Can you explain this clearly in an interview?

Use the strong answer as your reference, explain it aloud in your own words, then choose how soon you want to review it again.

Interview prompt

Spring Beans, Configuration, and AOP

Explain it aloud in your own words

Strong answer

Bean definitions describe how the container creates and manages objects. Profiles and configuration properties separate environment concerns from code. AOP can centralize cross-cutting behavior such as transactions or logging, but proxy-based behavior has boundaries and should not hide important domain logic.

Key points

  • Singleton scope means one bean instance per application context, not one object for every JVM ever.
  • Self-invocation can bypass proxy-based advice.
  • Configuration should be typed and validated where possible.
  • AOP is best for consistent cross-cutting policies, not core business decisions.

Interviewer looks for

Mention proxy boundaries, lifecycle, profiles, and why configuration should remain observable and testable.

Java example

1@Configuration
2class AppConfig {
3  @Bean
4  Clock clock() { return Clock.systemUTC(); }
5}

Topic interview questions

Revise this topic like an interviewer

These questions are tied to this lesson. Read each question aloud, then compare your explanation with the strong answer.

5 questions
Q1Intermediate

What does singleton scope mean in Spring?

Strong answer

It means one bean instance per application context, not one object for every JVM or every request. Singleton beans should be designed to be stateless or thread-safe when accessed concurrently.

Q2Intermediate

What is the purpose of bean lifecycle callbacks?

Strong answer

Initialization callbacks prepare a fully constructed bean, and destruction callbacks release resources when the context closes. They should manage lifecycle concerns, not contain the core business workflow.

Q3Intermediate

How do Spring profiles help?

Strong answer

Profiles select environment-specific bean definitions or configuration, such as local, test, and production integrations. They should not hide major business behavior or become an unmanageable collection of branching rules.

Q4Intermediate

Why can self-invocation bypass @Transactional or other AOP advice?

Strong answer

Spring commonly applies advice through a proxy. A method calling another method on the same this reference does not pass through the proxy, so the intercepting advice is not invoked.

Q5Intermediate

When is AOP a good fit?

Strong answer

AOP is useful for consistent cross-cutting policies such as transactions, metrics, tracing, and security. Core domain decisions should remain visible in ordinary code so they are easy to understand and test.

How well do you know this?

Your review choice is saved locally and synced to your learner profile when signed in.