Spring MVC applications with the archetype plugin

Spring Model View Controller (MVC) is a web application framework developed under the Spring framework, which is an open source application framework and an inversion of control container. Here, we will see how to generate a template Spring MVC application using the spring-mvc-quickstart archetype.

Note

To know more about the Spring MVC framework, refer to http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html.

Currently, the spring-mvc-quickstart archetype is not available in any of the public Maven repositories, so we have to download it from GitHub and build from the source, as follows:

$ git clone https://github.com/kolorobot/spring-mvc-quickstart-archetype.git
$ cd spring-mvc-quickstart-archetype
$ mvn clean install

Once the archetype is built from the source and is available in the local Maven repository, you can execute the following command to generate the template Spring MVC application:

$ mvn archetype:generate -B
         -DarchetypeGroupId=com.github.spring-mvc-archetypes
         -DarchetypeArtifactId=spring-mvc-quickstart
         -DarchetypeVersion=1.0.0-SNAPSHOT
         -DgroupId=com.packt.samples
         -DartifactId=my-spring-app
         -Dpackage=com.packt.samples.spring
         -Dversion=1.0.0

This will produce the following project template:

my-spring-app
         |-pom.xml
         |-src/main/java/com/packt/samples/spring/Application.java
         |-src/main/webapp/WEB-INF/views
         |-src/main/webapp/resources
         |-src/main/resources
         |-src/test/java/com/packt/samples/spring
         |-src/test/resources

Let's see how to run the template Spring MVC application with the embedded Tomcat via Maven itself. Embedded Tomcat can be launched via the run goal of the tomcat7 plugin, which is shown in the following code. Once the server is up, you can browse through to the web application via http://localhost:8080/my-spring-app.

$ mvn test tomcat7:run

Note

More details about the tomcat7 plugin is available at http://tomcat.apache.org/maven-plugin-trunk/tomcat7-maven-plugin/.

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

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