TestMultiModuleTest 為父項(xiàng)目,其余為子模塊
test-api 存放bean和service的接口卡骂,普通的maven模塊崔慧,沒(méi)有選擇archetype
test-provider 存放dao和service接口的實(shí)現(xiàn)狠半,spring和mybatis的配置文件宰翅,普通的maven模塊弃甥,沒(méi)有選擇archetype。依賴于test-api模塊堕油,需要在該模塊的pom.xml中添加
test-web 存放controller和springMVC的配置文件潘飘,選擇archetype為maven-archetype-webapp。依賴于test-api掉缺,test-provider模塊,需要在該模塊的pom.xml中添加
項(xiàng)目 TestMultiModuleTest pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.shpun</groupId>
<artifactId>TestMultiModuleTest</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>test-web</module>
<module>test-provider</module>
<module>test-api</module>
</modules>
<dependencyManagement>
<!-- 依賴管理戈擒,子模塊根據(jù)需要從父項(xiàng)目的獲取 -->
</dependencyManagement>
</project>
模塊 test-api pom.xml 不變
模塊 test-provider pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>TestMultiModuleTest</artifactId>
<groupId>com.shpun</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>test-provider</artifactId>
<dependencies>
<!-- 模塊test-api依賴 -->
<dependency>
<groupId>com.shpun</groupId>
<artifactId>test-api</artifactId>
<version>${project.parent.version}</version>
</dependency>
<!-- 無(wú)需添加<version></version>標(biāo)簽 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency
</dependencies>
</project>
模塊 test-web pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>TestMultiModuleTest</artifactId>
<groupId>com.shpun</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>test-web</artifactId>
<packaging>war</packaging>
<name>test-web Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<!-- 模塊test-api依賴 -->
<dependency>
<groupId>com.shpun</groupId>
<artifactId>test-api</artifactId>
<version>${project.parent.version}</version>
</dependency>
<!-- 模塊test-provider依賴 -->
<dependency>
<groupId>com.shpun</groupId>
<artifactId>test-provider</artifactId>
<version>${project.parent.version}</version>
</dependency>
</dependencies>
<build>
<finalName>test-web</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
項(xiàng)目結(jié)構(gòu)
項(xiàng)目列表
模塊test-api
模塊test-provider
模塊test-web
總結(jié)
一開(kāi)始test-provider和test-web兩個(gè)模塊都是webapp眶明,兩個(gè)模塊的spring配置文件分開(kāi)讀取。test-provider讀取spring筐高,mybatis配置文件搜囱;test-web讀取springMVC配置文件。但在test-provider中的spring的配置文件一直讀取不到柑土,classpath:和classpath*:都不行蜀肘。部署的有兩個(gè)webapp,分兩個(gè)tomcat部署也不行稽屏,合并部署也不行扮宠。留個(gè)坑。
分開(kāi)讀取配置文件待解決
改成在test-web中的web.xml讀取所有的配置文件classpath:application-.xml狐榔。