自存,maven,springboot,多模块

创建一个maven项目,在pom.xml文件下有自己的坐标地址

直接把这个坐标引入其他模块,就相当于引入了这个模块的所有依赖,还有这个模块的类

如果是父子模块,那么子组件是这样的

如果要引入到其他模块里面,groupId和version都是一样的,artfaceId为下面的(cs)也就是这个模块的名字。

引入了这个模块,就相当于引入了这个模块的依赖和类

例如,我在cs模块创建了一个方法,然后我在springbootdeom模块引入cs模块,然后调用cs的方法

可以调用

然后就是一些接口问题,springboot项目引入其他模块的依赖,然后在其他模块写controller接口层

例如,我在cs的 src/main/java/com/example/springboot_demo路径下写了一个接口,这个路径和spring boot的路径一样的

启动项目测试一下

发现测试成功

但如果我把cs的controller放在上一个目录的位置就不行了

起初我想的是cs模块和springbootdemo模块本来就不在一个目录下,为什么bean类还是要遵守在springboot启动类下面,

后面我猜想的是,引入依赖的时候就相当于把两个模块的目录进行了合并,所有虽然是两个模块,但目录结构都要一样的

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用 Maven 进行 springboot模块单元测试和 Jacoco 代码覆盖率统计。 对于多模块项目,需要在父 POM 文件中添加 Jacoco 插件配置,以及指定子模块的测试目录: ```xml <modules> <module>module1</module> <module>module2</module> <module>module3</module> </modules> <build> <plugins> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.7</version> <executions> <execution> <id>prepare-agent</id> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>report-aggregate</id> <phase>test</phase> <goals> <goal>report-aggregate</goal> </goals> </execution> </executions> <configuration> <skip>true</skip> </configuration> </plugin> </plugins> </build> <profiles> <profile> <id>unit-test</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.2</version> <configuration> <skipTests>false</skipTests> <skip>false</skip> <forkCount>1</forkCount> <reuseForks>true</reuseForks> <argLine>${jacoco.agent.argLine}</argLine> <excludedGroups>org.junit.experimental.categories.ExcludeCategory</excludedGroups> <testFailureIgnore>true</testFailureIgnore> <includes> <include>**/*Test.java</include> </includes> </configuration> <dependencies> <dependency> <groupId>org.junit.platform</groupId> <artifactId>junit-platform-surefire-provider</artifactId> <version>1.6.2</version> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.6.2</version> </dependency> </dependencies> </plugin> </plugins> </build> </profile> </profiles> <modules> <module>module1</module> <module>module2</module> <module>module3</module> </modules> <profiles> <profile> <id>unit-test</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.2</version> <configuration> <skipTests>false</skipTests> <skip>false</skip> <forkCount>1</forkCount> <reuseForks>true</reuseForks> <argLine>${jacoco.agent.argLine}</argLine> <excludedGroups>org.junit.experimental.categories.ExcludeCategory</excludedGroups> <testFailureIgnore>true</testFailureIgnore> <includes> <include>**/*Test.java</include> </includes> </configuration> <dependencies> <dependency> <groupId>org.junit.platform</groupId> <artifactId>junit-platform-surefire-provider</artifactId> <version>1.6.2</version> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.6.2</version> </dependency> </dependencies> </plugin> </plugins> </build> </profile> </profiles> ``` 这个配置会在编译和测试时启动 Jacoco 代理,同时在测试后生成 Jacoco 报告。 同时,可以使用 Maven Profiles 来区分测试和生产环境的配置,例如上面的配置中就定义了一个名为 `unit-test` 的 Profile。在执行单元测试时,可以使用命令 `mvn clean test -Punit-test` 来指定使用 `unit-test` Profile。 对于单个模块的项目,可以在模块的 POM 文件中添加 Jacoco 插件配置: ```xml <build> <plugins> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.7</version> <executions> <execution> <id>prepare-agent</id> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>report</id> <phase>test</phase> <goals> <goal>report</goal> </goals> </execution> </executions> <configuration> <skip>true</skip> </configuration> </plugin> </plugins> </build> ``` 这个配置会在编译和测试时启动 Jacoco 代理,同时在测试后生成 Jacoco 报告。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值