网址:https://blog.csdn.net/kity9420/article/details/53292084
https://www.2cto.com/kf/201704/621169.html
maven多模块项目SpringMVC简单实例:划分多模块,也就是方便多人开发,自己开发自己的那块没有多大冲突。
项目结构
整个项目目录是这样的:
GitHub地址 :https://github.com/thecattle/maven_model
—- app-parent
|– pom.xml (pom)
|
|– app-dao
| |– pom.xml (jar)
|
|– app-service
| |– pom.xml (jar)
|
|– app-web
|– pom.xml (war)
注意他们的packaging类型,有jar,war和pom三种
dao–作为jar导入–>service–作为jar导入–>web–build成war项目–>运行
项目搭建
父模块仅仅是帮助聚合其他模块构建的工具,它本身并无实际的内容。
父模块与其他模块的目录结构并非一定是父子关系,还可以是平行关系。更改下modules路径即可。
首先new一个maven项目作为parent项目。
pom文件如下:
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 41 42 43 44 45 46 47 48 49 50 |
|
再new一个maven项目作为dao模块。pom文件如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
再new一个maven项目作为service模块,pom如下:
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 |
|
再new一个maven项目作为web模块,pom如下:
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 |
|
现在这三个模块就已经关联起来了
配置SpringMVC
在web模块中,web.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 |
|
spring-mvc.xml:
<!--?xml version=
"1.0"
encoding=
"UTF-8"
?-->
<beans xmlns=
"https://www.springframework.org/schema/beans"
xmlns:context=
"https://www.springframework.org/schema/context"
xmlns:xsi=
"https://www.w3.org/2001/XMLSchema-instance"
xsi:schemalocation=
"https://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd https://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd"
>
<!--扫描com.sun下的所有包-->
<context:component-scan base-
package
=
"com.sun.**"
>
</context:component-scan></beans>