之前我在写SpringMVC花了很多篇幅,所以很多关于SpringMVC的很多知识点可以参考我以前的笔记。
Servlet3.0以上可以不使用web.xml进行配置,而是实现Spring提供的WebApplicationInitializer接口进行相关的Web配置。当然我们的web服务器也需要时tomcat7.x以上版本。
现在我们首先看看我们这个实验环境的maven pom文件:
<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.tony</groupId> <artifactId>AnnotationSpringmvc</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>AnnotationSpringmvc Maven Webapp</name> <url>http://maven.apache.org</url> <repositories> <repository> <id>io.spring.repo.maven.release</id> <url>http://repo.spring.io/release/</url> </repository> <repository> <id>maven-eu.nuxeo.org</id> <url>https://maven-eu.nuxeo.org/nexus/content/repositories/public-releases/</url> </repository> </repositories> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <spring.version>4.3.9.RELEASE</spring.version> </properties> <dependencies> <!-- https://mvnrepository.com/artifact/junit/junit --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/commons-io/commons-io --> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.5</version> </dependency> <!-- https://mvnrepository.com/artifact/javax.servlet/servlet-api --> <dependency> <groupId>javax.servlet