最终我们的项目看起来是这样的:
可以在Maven官网:http://search.maven.org/ 进行搜索需要的依赖配置。下面是具体的依赖配置:
pom.xml
4.0.0
com.boonya.spring.mvc.velocity
SpringVelocity
0.0.1-SNAPSHOT
war
http://maven.apache.org
javax.servlet
javax.servlet-api
3.1.0
org.springframework
spring-web
3.2.5.RELEASE
org.springframework
spring-webmvc
3.2.5.RELEASE
org.springframework
spring-core
3.2.5.RELEASE
org.apache.velocity
velocity
1.7
com.googlecode.sli4j
sli4j-slf4j-log4j
2.0
junit
junit
4.11
test
net.sf.ehcache
ehcache-core
2.6.5
org.codehaus.jackson
jackson-mapper-asl
1.9.13
net.sf.json-lib
json-lib
2.4
jdk15
org.springframework
spring-core
3.2.5.RELEASE
org.springframework
spring-context-support
3.2.4.RELEASE
jar
compile
org.mybatis
mybatis-spring
1.2.1
org.mybatis
mybatis-ehcache
1.0.0
org.springframework
spring-jdbc
3.2.5.RELEASE
com.alibaba
druid
1.0.2
org.apache.poi
poi
3.8
org.springframework
spring-webmvc
3.2.5.RELEASE
commons-httpclient
commons-httpclient
3.1
org.apache.cxf
cxf-rt-frontend-jaxws
2.7.6
wsdl4j
wsdl4j
1.6.3
jar
compile
org.springframework
spring-beans
3.2.5.RELEASE
org.springframework
spring-test
3.2.5.RELEASE
test
org.aspectj
aspectjweaver
1.7.4
mysql
mysql-connector-java
5.1.12
org.mybatis
mybatis
3.1.1
javax
javaee-api
6.0
provided
javax.mail
mail
1.4.7
javax.servlet
jstl
1.2
commons-fileupload
commons-fileupload
1.3
org.apache.clerezza.ext
org.json.simple
0.3-incubating
compile
com.alibaba
fastjson
1.1.41
dom4j
dom4j
1.6
com.google.zxing
core
3.0.1
net.coobird
thumbnailator
0.4.8
org.springframework
spring-orm
3.2.5.RELEASE
org.unitils
unitils-core
3.1
test
org.unitils
unitils-database
3.1
test
org.unitils
unitils-dbmaintainer
3.1
test
org.unitils
unitils-dbunit
3.1
test
org.unitils
unitils-spring
3.1
test
org.unitils
unitils-orm
3.1
test
org.quartz-scheduler
quartz
1.8.5
org.apache.maven.plugins
maven-compiler-plugin
2.3.2
1.7
org.mybatis.generator
mybatis-generator-maven-plugin
1.3.1
false
org.apache.tomcat.maven
tomcat7-maven-plugin
2.1
utf-8
8888
/
false
false
org.codehaus.mojo
tomcat-maven-plugin
1.1
http://192.168.200.121:8080/manager/text
tomcat
password
/SpringVelocity
src/main/resources
**/*.properties
**/*.xml
src/main/java
**/*.java
**/.svn/*
web.xml
Archetype Created Web Application
spring
org.springframework.web.context.ContextLoaderListener
springServlet
org.springframework.web.servlet.DispatcherServlet
spring mvc
contextConfigLocation
/WEB-INF/spring-servlet.xml
springServlet
*.html
Spring通用配置:applicationContext.xml
SpringMVC的配置:spring-servlet.xml
SpringVelocityController.java
package com.boonya.spring.mvc.velocity.controller;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class SpringVelocityController {
@RequestMapping("/velocity")
public ModelAndView velocityView(HttpServletRequest req, HttpServletResponse resp) throws Exception {
System.out.println("------------ enter SpringVelocityController");
List list = new ArrayList();
list.add("a");
list.add("b");
list.add("c");
return new ModelAndView("velocity", "list", list);// velocity:即SpringVelocity/src/main/webapp/WEB-INF/templates/velocity.vm
}
}
我们加一个空的JSP页面作为首页:index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
SpringVelocity首页
欢迎来到,SpringVelocity!
启动tomcat访问:http://localhost:8080/SpringVelocity/ 看到以下输出说明配置可以正常启动。
在浏览器输入:http://localhost:8080/SpringVelocity/velocity.html 如果看到如下输出则配置成功。
还是那句话,实践出真知。文章有借鉴阿里实习小朋友的(文章上面有误):http://blog.csdn.net/sun_wangdong/article/details/51992194
http://download.csdn.net/detail/boonya/9752942