创建一个Hello world的例子,使用Java配置。 通过对应的Java替换XML配置。
以 Spring Java为基础的配置取决于Servlet 3.0 的API, 因此,我们需要包含的依赖在 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.dhb.demo</groupId>
<artifactId>spring4MVCHelloWorldNoXMLDemo</artifactId>
<packaging>war</packaging>
<version>0.1.0-SNAPSHOT</version>
<name>spring4MVCHelloWorldNoXMLDemo Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<jetty.context>/</jetty.context>
<jetty.http.port>9089</jetty.http.port>
<jetty.https.port>9444</jetty.https.port>
<jetty.stopPort>10081</jetty.stopPort>
<spring.version>4.1.4.RELEASE</spring.version>
</properties>
<dependencies>
<!-- spring -->
<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>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
<!--maven jetty 插件配置-->
<plugin>
<groupId>org.eclipse.jetty</groupId>