Hello World App with Spring Framework 4 & Maven 3 - Part I - 2020

bogotobogo.com site search:
Note
Eclipse:

Maven 3:
$ mvn -v Apache Maven 3.0.5 Maven home: /usr/share/maven Java version: 1.7.0_65, vendor: Oracle Corporation Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "3.13.0-35-generic", arch: "amd64", family: "unix"
Eclipse Maven Project Setup
Maven project archetype in Eclipse will create a layout required for our web project:
File -> New -> Other... -> Maven -> Maven Project:


Pick the maven-archetype-webapp:

Set GroupId Artifact Id as below:

Click on "Finish" to finish Maven project setup, and the project looks like this:

Configuring Spring - pom.xml
We now need to add the spring framework libraries as dependencies in Maven (pom.xml). We'll also define a maven variable to hold the Spring framework version.
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.bogotobogo</groupId> <artifactId>spring4-helloWorld</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>Spring4HelloWorldMavenWebapp</name> <url>http://maven.apache.org</url> <properties> <spring.version>4.0.1.RELEASE</spring.version> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <!-- Spring dependencies --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> </dependencies> <build> <finalName>Spring4HelloWorld</finalName> </build> </project>
After updating the pom.xml, We can see the Spring libraries have been added to Maven dependencies:

Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization