Annotations

[1] @Component

annotation marks a java class as a bean so the component-scanning can dicover this bean and register into the application context. To use this annotation, apply it over class as below:

@Component

public class EmployeeDAOImpl implements EmployeeDAO {

...

}

[2] @Repository annotation

is a specialization of the @Component annotation with similar use and functionality. In addition to register the DAOs into the IOC container, it converts ORM and HDBC specific exceptions into generic Spring DataAccessException exception hierarchy.

[3] @Service

@Service annotation is also a specialization of the component annotation. It doesn’t currently provide any additional behavior over the @Component annotation, but it’s a good idea to use @Service over @Component in service-layer classes because it specifies intent better.

[4]@Controller annotation marks a class as a Spring Web MVC controller. It is also the specialized form of @Component. When you add the @Controller annotation to a class, you can use another annotation i.e. @RequestMapping; to map URLs to instance methods of a class.

[5] @RequestMapping

Maps URL path to a Controller class or its methods.

[6] @RequestParam:

Binds request parameters to method parameters.

[7] @ModelAttribute()

Binds object to a Model.

[8] @Valid

Applies validation to a Form

[9] @InitBinder :

Custom binder is used to convert String into Date, Time or other objects and vice versa. Custom binder will be used to bind request parameters to Form beans. It is specifically used to bind Date and Time form attributes.

[10] @CookieValue

The @CookieValue annotation allows a method parameter to be bound to the value of an HTTP cookie.

public void display(@CookieValue("JSESSIONID") String sid) {

//...

}

[11] @RequestHeader

The @RequestHeader annotation allows a method parameter to be bound to a request header.

Here is a sample request header:

Host localhost:8080

Accept text/html,application/xhtml+xml,application/xml;q=0.9

Accept-Encoding gzip,deflate

Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive 300

public void display(@RequestHeader("Accept-Encoding") String encoding,

@RequestHeader("Keep-Alive") long keepAlive) {

//...

}

When an @RequestHeader annotation is used on a Map<String, String>, MultiValueMap<String, String>, or HttpHeaders argument, the map is populated with all header values.