@Configuration and @Bean
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
@Beanmethods 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
@Beanmethod are injected like constructor parameters.
Draft outline details
Demonstration
@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.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.