May 2015
Intermediate to advanced
234 pages
4h 18m
English
Spring configuration beans, such as the one in the Defining a bean explicitly with @Bean recipe are automatically discovered and used by Spring. To use a bean (any kind of bean) in one of your classes, add the bean as a field and annotate it with @Autowired. Spring will automatically initialize the field with the bean. In this recipe, we'll use an existing bean in a controller class.
We will use the code from the Defining a bean implicitly with @Component recipe, where we defined a UserService bean.
Here are the steps to use an existing bean in one of your classes:
UserService field annotated with @Autowired:@Autowired UserService userService; ...
Read now
Unlock full access