今天整理一下一个用springMVC写得helloworld需要依赖哪些包
我们配置一个springMVC的时候
首先是配置web.xml
将请求交给spring的DispatcherServlet处理
代码如下
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
其次配置springmvc-servlet.xml
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
根据DispatcherServlet的完整路径来看,我们需要加入
spring-web-4.x.x.RELEASE.jar
接着启动服务查看报错并加入相关的jar
错误如下:
java.lang.NoClassDefFoundError: org/springframework/beans/factory/BeanNameAware
根据错误加入
spring-beans-4.x.x.RELEASE.jar
接着报错
java.lang.NoClassDefFoundError: org/springframework/context/EnvironmentAware
继续加入
spring-context-4.x.x.RELEASE.jar
接着报错
java.lang.NoClassDefFoundError: org/springframework/core/env/Environment
继续加人
spring-core-4.x.x.RELEASE.jar
接着报错
org/apache/commons/logging/LogFactory
继续加入
commons-logging-1.1.3.jar
接着报错
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
嗯?这个错是说找不到DispatcherServlet吗,可是在刚开始都已经将
spring-web-4.x.x.RELEASE.jar
加入了吗?
原来DispatcherServlet虽然前缀是org.springframework.web.servlet可是它并不在spring-web-4.x.x.RELEASE.jar中
它在
spring-webmvc-4.x.x.RELEASE.jar
中,好,将其加入
接着报错
java.lang.NoClassDefFoundError: org/springframework/aop/TargetSource
引入
spring-aop-4.x.x.RELEASE.jar
接着报错
java.lang.NoClassDefFoundError: org/springframework/expression/ParserContext
引入
spring-expression-4.x.x.RELEASE.jar
到这里已经不报错了
然后开发Controller
写一个helloworld
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
最后开发展示层
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
好了打开浏览器访问
http://localhost:8080/springmvctest/hello/world.html
一个简单的helloworld完成
最后的最后贴上项目结构和jar包的结构还有下载jar包的地址
我的Dynamic Web Module 是3.0的
项目结构
jar包下载地址
推荐使用Maven中央仓库,当然这个项目也可以建成一个maven项目
Maven中央仓库地址