written by Ivan Cerrato
JEE Tomcat Spring Maven Hibernate MySql Eclipse
Spring_1.  Spring  MVC. Maven. Eclipse.  In this tutorial we provide a tutorial starting from vacuum  to make a new spring- maven based project. The IDE tool to mangage the project is Eclipse. Asswuming that you have created a specific directory as your workspace, for instance /Users/ivan/Documents/workspacelet’s continue going  into the directory and typing  from command linemvn archetype:generate -DgroupId="it.extremetechnologies" -DartifactId=Spring_1 -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false afer the creation   mvn eclipse:eclipse -Dwtpversion=2.0 - then import it in eclipse after that  - Maven -> disable maven nature mvn eclipse:clean - Configure -> Convert To Maven Project After that, if you see  an error of type "Cannot change version of project facet Dynamic Web Module to 2.3.” open the deployment descriptor, the  web.xml,  and make the following changes :   Archetype Created Web Application          Spring_1     org.springframework.web.servlet.DispatcherServlet     1         Spring_1     /            contextConfigLocation     classpath:applicationContext.xml       org.springframework.web.context.ContextLoaderListener         Rebuild the project and you'll see the error disappeared. This way we update the web-app to version 3.0 and we add the notations to add the  DispatcherServlet. Now open the Run configuration and add the goals to the new created configuration to build the app: clean package cargo:deploy The cargo:deploy goal is the goal we use to deploy the war into Tomcat. To use that we must supply some information to pom. And, yet, we will provide in the pom all the dependencies necessaries to complete the next steps to achieve our entire web-app.  In essence we add the libraries dependencies to the  pom to integrate spring, logging, junit, hibernate.
back to home
  4.0.0   it.seat   Spring_1   war   1.0-SNAPSHOT   Spring_1 Maven Webapp   http://maven.apache.org JBoss repository http://repository.jboss.org/nexus/content/groups/public/    3.2.6.RELEASE   3.6.7.Final   /usr/local/apache-tomcat-7.0.34 … … …             junit       junit       3.8.1       test     … … ...        ${webappDirectory}/WEB-INF/classes ${project.artifactId} src/main/resources org.apache.maven.plugins maven-compiler-plugin 2.3.1 1.6 1.6             org.codehaus.cargo         cargo-maven2-plugin         1.1.4                               tomcat7x             ${appserver.home}                                                               ${build.finalName}                           ${appserver.home}                      To see the entiree pom you can download it from the download section.
Now in the /Spring_1/src/main/webapp/WEB-INF/ add the  file Spring_1-servlet.xml to cofigure spring annotation , the resolver, in our case we provide jsp pages, the mvc annotation support and the bean for ReloadableResourceBundleMessageSource and context:component-scan to retieve the controllers.     Ok, now it’s time to add the controllers. before that delete the Spring_1/src/main/webapp/index.jsp. After, make the package with the hierarchy it.extremetechnologies.Spring_1.controller in the tree /Spring_1/src/main/java Now create the file  HomeController.java in the package. This file will contains the notation @Controller and the notation @RequestMapping(value = "/", method = RequestMethod.GET) to permits Spring to associate the path to the correct controller. See it in the download section. Now in the src/main/resources add the filesapplicationContext.xml log4j.properties messages_en.properties they are respectively, the setting for the application context, the setting for the log4j and the messages used by org.springframework.context.support.ReloadableResourceBundleMessageSource. See it in the download section. Now make the pages directory under /Spring_1/src/main/webapp/WEB-INF/and under pages make the file page_1.jsp with a similar structure: <%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>     Spring_1    hi there... Rebuild all. Restart Tomcat. And from in your browser type you’ll see the message coming from your web app.
Download section.