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
- @RestController - HTTP requests are handled by a controller. These components are easily identified by the
@RestControllerannotation.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 aGreetingobject. The object data will be written directly to the HTTP response as JSON.This code uses Spring 4’s new@RestControllerannotation, which marks the class as a controller where every method returns a domain object instead of a view. It’s shorthand for@Controllerand@ResponseBodyrolled together.TheGreetingobject 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’sMappingJackson2HttpMessageConverteris automatically chosen to convert theGreetinginstance to JSON. - @RequestMapping - The
@RequestMappingannotation ensures that HTTP requests to/greetingare mapped to thegreeting()method. - @RequestParam -
@RequestParambinds the value of the query string parameternameinto thenameparameter of thegreeting()method. This query string parameter is notrequired; if it is absent in the request, thedefaultValueof "World" is used.
No comments:
Post a Comment