Maven工程问题
建立一个父模块,里面加入两个子模块 其中vhr-model是一个普通的模块,vhr-web是一个SpringBoot模块,vhr-model和vhr-web都是vhr模块的子模块,vhr-web的子模块依赖于vhr-model的子模块 pom.xml(vhr):
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.2</version>
<relativePath/>
</parent>
<groupId>org.dong</groupId>
<artifactId>vhr</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>vhr-model</module>
<module>vhr-web</module>
</modules>
pom.xml(vhr-model):
<parent>
<artifactId>vhr</artifactId>
<groupId>org.dong</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>vhr-model</artifactId>
pop.xml(vhr-web):
<parent>
<groupId>org.dong</groupId>
<artifactId>vhr</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>vhr-web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>vhr-web</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.dong</groupId>
<artifactId>vhr-model</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
在打包的过程中,vhr-web不能直接单独打包,因为vhr-web对vhr-model有依赖,否则会报错。如果在parent模块中加入如下代码,在打包父模块的过程程中会把所有的子模块也全部打包,但是子模块不能独立打包,去掉之后子模块才能独立打包,但是有依赖于其他子模块的模块是不能独立打包的。
<modules>
<module>vhr-model</module>
<module>vhr-web</module>
</modules>
SpringBoot-start-parent中Resource问题
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/application*.yml</include>
<include>**/application*.yaml</include>
<include>**/application*.properties</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src/main/resources</directory>
<excludes>
<exclude>**/application*.yml</exclude>
<exclude>**/application*.yaml</exclude>
<exclude>**/application*.properties</exclude>
</excludes>
</resource>
</resources>
说明:建立一个Maven工程和两个配置文件测试,配置文件中加入a.name=${dong.name} pom.xml:
<groupId>org.dong</groupId>
<artifactId>demo06</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<dong.name>www.dong.name</dong.name>
</properties>
打包之后,两个配置文件并没有想象中的把${dong.name}替换为www.dong.name,这是由于没有配置pom.xml文件,配置之后
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>a.properties</include>
</includes>
</resource>
</resources>
</build>
a.properties文件正常运行,${dong.name}成功替换为www.dong.name,而b.properties并没有成功,显然是include的作用将配置文件加载进去,但是因为过滤器的缘故所以b.properties被过滤掉,没有被打包进去
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>a.properties</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>a.properties</exclude>
</excludes>
</resource>
</resources>
</build>
加入以上配置之后就会发现,b.properties没有滤掉,而是被打包进来,但是${dong.name}也没有替换为www.dong.name,这就是resource配置的作用
spring-boot-starter-parent问题
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.2</version>
<relativePath/>
</parent>
如果配置文件中同一个配置文件用$符号引用了本文件中的变量,那么就需要resource.delimiter中@符号来已引用pom.xml中用properties配置的变量
a.name=dong
b.name=${a.name}
c.name=@dong.name@
上图中是parent的父依赖,里面定义了编译版本号 Maven是单继承
|