Pages

Thursday, 17 July 2014

Spring Annotations

What is dependency injection ?
Expanding this into a real system, we might have dozens of such services and components. In each case we can abstract our use of these components by talking to them through an interface (and using an adapter if the component isn't designed with an interface in mind). But if we wish to deploy this system in different ways, we need to use plugins to handle the interaction with these services so we can use different implementations in different deployments.
http://martinfowler.com/articles/injection.html 
http://stackoverflow.com/questions/tagged/spring 

Unit testing : http://docs.spring.io/spring/docs/2.5.x/reference/index.html
 
  1. @RestController - HTTP requests are handled by a controller. These components are easily identified by the @RestController annotation.
    A key difference between a traditional MVC controller and the RESTful web service controller above is the way that the HTTP response body is created. Rather than relying on a view technology to perform server-side rendering of the greeting data to HTML, this RESTful web service controller simply populates and returns a Greeting object. The object data will be written directly to the HTTP response as JSON.
    This code uses Spring 4’s new @RestController annotation, which marks the class as a controller where every method returns a domain object instead of a view. It’s shorthand for@Controller and @ResponseBody rolled together.
    The Greeting object must be converted to JSON. Thanks to Spring’s HTTP message converter support, you don’t need to do this conversion manually. Because Jackson 2 is on the classpath, Spring’s MappingJackson2HttpMessageConverter is automatically chosen to convert the Greeting instance to JSON.
  2. @RequestMapping - The @RequestMapping annotation ensures that HTTP requests to /greeting are mapped to the greeting() method.
  3. @RequestParam -  @RequestParam binds the value of the query string parameter name into the nameparameter of the greeting() method. This query string parameter is not required; if it is absent in the request, the defaultValue of "World" is used.
  4.   

No comments:

Post a Comment