Friday, June 25, 2021

What is annotations?

 Annotations are meta data about a class that will be processed by compiler at runtime or compile time.

Ex: when we override a method of parent class then always we see a @Override annotation that is processed at compile time . It actually inform compiler that we are overriding a method .Then compiler check the classes .

when we use annotation in spring ,the it will scan java classes for special annotation.

Automatically register bean to spring container based on annotations.

Ex:

@Component("person")

public class Person extend Human{

}

here spring will scan for component and register this class as bean to spring container .

Using the bean id "person" we can able to retrieve the bean from spring container.

Retrieve bean from spring container,

Person person = context.getBean("person",Person.class);

here context is the ApplicationContext which is spring container.

No comments:

Post a Comment

Fluent interface pattern

 public class UserConfigurationManager {     private String userName;     private String password;     private UserConfigurationManager() { ...