What are the annotations in Spring Boot Application ?
#Motivation This is also an interview asked question so i dig deep into it and learned most of the annotations that were used in spring framework
autowired
it is introduced from spring 2.5 and it will resolved and inject the collaborating beans into our bean
autowired can be used with properties,setter methods and constructors
Lets say there is a service called postService and call called postFormatter
@Component
public class PostFormatter {
public String format() {
return "foo";
}
}
This is post Service : applying on properties
@Component
public class PostService {
@Autowired
private PostFormatter postformat;
}
Setters methods
public class FooService {
private FooFormatter fooFormatter;
@Autowired
public void setFooFormatter(FooFormatter fooFormatter) {
this.fooFormatter = fooFormatter;
}
}
Construstor.
@Component This annotation is a class level annotation it tells spring to create and manage the bean creation with spring Container
Bean --> this is a method level annotation it will be applied to a method that can return a bean which is maintained by the spring container.
@Controller
is used on the class, the is contains the methods which will be used by the clients```@RequestMapping this will be applied to the methods int eh controller
@Service
: Class level will be applied where the business logic written` @Repository
: class level will be applied to class Dao which will interact with databaseComponetScan --> will scan all the classes in the packages.