Creating Spring context

 

Now that we have DispatcherServlet defined in web.xml, we can go ahead and create our Spring context. Initially, we will create a very simple context without really defining anything concrete:

    <beans > <!-Schema Definition removed --> 
<context:component-scan
base-package="com.mastering.spring.springmvc" />
<mvc:annotation-driven />
</beans>

 

We are defining a component scan for the com.mastering.spring.springmvc package so that all the beans and controllers in this package are created and auto-wired.

Using <mvc:annotation-driven/> initializes support for a number of features that Spring MVC supports such as:

  • Request mapping
  • Exception handling
  • Data binding and validation
  • Automatic conversion (for example, JSON) when the @RequestBody annotation is used

That's all the setup we need to be able to set up a Spring MVC application. We are ready to get started with the first flow.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset