Skip to content
Ameen Abozaid
Planned lessonJNR-010-L03

@Configuration and @Bean

  • Lesson 3 of 6
  • Junior
On This Lesson 4 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

register beans you cannot annotate.

Planned topics

  • Use @Bean methods when the class is third-party or needs set-up code.
  • Put them in a class marked @Configuration.
  • The method name is the bean name; the return type is the bean type.
  • Parameters of a @Bean method are injected like constructor parameters.
Draft outline details

Demonstration

java
@Configuration
class AppConfig {
    @Bean Clock clock() { return Clock.systemUTC(); }
}

Check your understanding

When @Bean instead of @Component?

Show answer

When you cannot edit the class, or it needs custom construction.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.