Database Reference
In-Depth Information
Spring Web MVC
The Spring Web model-view-controller (SWMVC) is the Spring implementation of a model-view-controller (MVC)
framework. The aim of the framework is to help you quickly build out powerful web applications and APIs using only
what is absolutely necessary to get the job done. The SWMVC library and its dependencies are included with the
sample application and should not require any additional configuration beyond what is provided in this chapter to
run the application.
As with other MVC frameworks, one of the most important aspects of SWMVC is the handling of routing.
The use of annotations allows routing to be placed directly within the controller class. Listing 11-1 shows that the
HomeController uses the @RequestMapping annotation and sets its path as root. The home method is the default
method executed in this example. In addition to enabling you to see the mapping settings at a glance, it allows you to
configure and view the specific methods and results within the class file.
Listing 11-1. Example of a Controller and Its Annotations
@Controller
@RequestMapping("/")
public class HomeController extends GraphStoryController {
@RequestMapping(method = RequestMethod.GET)
public String home(Locale locale, Model model) {
// add page title
model.addAttribute("title", "Home");
// return page to display
return "/mustache/html/home/index.html";
}
}
The sample application will use a file named applicationContext.xml , which resides in the /WEB-INF directory.
I will cover its configuration in the sample application section of this chapter.
Hosts File
To keep each chapter separated in terms of the webserver or container configuration, add a host name to your local
hosts file. The process for modifying the hosts file depends on your preferred operating system. For this chapter,
please add an entry to point 127.0.0.1 to practicalneo4j-spring.
Local Apache Tomcat Configuration
To follow the sample application later in this chapter, you need to configure your local Apache Tomcat to use the
workspace project in Eclipse as the document root. To do this, you need to modify the server.xml file, which can be
found at /TOMCAT-INSTALLATION-DIR/conf/server.xml, as shown in Listing 11-2. The most important changes are
adding a HOST and CONTEXT, as shown in the listing.
Using the method of pointing your hoST's appbase to your project within the workspace is one way to “hot
reload” code changes. This method is very helpful for most developers because server startup and restart times can be a
significant drain on productivity. The process of “deploy and run” has its positive aspects, but the minutes add up quickly.
Note
 
 
Search WWH ::




Custom Search