May 2015
Intermediate to advanced
234 pages
4h 18m
English
Beans don't have to be defined in a Spring configuration class. Spring will automatically generate a bean from any class annotated with @Component.
We will use the basic web application created in the Creating a Spring web application recipe in Chapter 1, Creating a Spring Application.
Create the com.springcookbook.service package and the following service class in it:
public class UserService {
public int findNumberOfUsers() {
return 10;
}
}Here are the steps to define a bean by adding @Component to an existing class:
@ComponentScan class annotation, add the com.springcookbook.service base package:@Configuration @EnableWebMvc @ComponentScan(basePackages ...
Read now
Unlock full access