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
@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 aGreeting
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.TheGreeting
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’sMappingJackson2HttpMessageConverter
is automatically chosen to convert theGreeting
instance to JSON. - @RequestMapping - The
@RequestMapping
annotation ensures that HTTP requests to/greeting
are mapped to thegreeting()
method. - @RequestParam -
@RequestParam
binds the value of the query string parametername
into thename
parameter of thegreeting()
method. This query string parameter is notrequired
; if it is absent in the request, thedefaultValue
of "World" is used.
No comments:
Post a Comment