maven聚合工程

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2023-08-31 21:48:51.440 ERROR 21888 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Field userService in com.zs.api.controller.UserController required a bean of type 'com.zs.service.service.UserService' that could not be found.

The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'com.zs.service.service.UserService' in your configuration.

Disconnected from the target VM, address: '127.0.0.1:49426', transport: 'socket'

Process finished with exit code 0

报如上错误,表示添加bean的时候没有将 UserService添加上去,需要在启动类加一个扫描

 @SpringBootApplication(scanBasePackages = "com.XX")

在聚合工程中测试时需要在pom.xml中加入两个依赖,之后在启动类所在模块进行测试,测试类需要加上

 @RunWith(SpringRunner.class)

 @SpringBootTest(classes = XXXApplication.class)

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
</dependency>

 在聚合工程中,父pom.xml负责管理依赖版本,子pom.xml可以引用,并且一个子工程引入后,另个一个子工程引入无需再添加相同依赖,因为依赖之间有继承关系x

mven三大作用:

  • 管理依赖
  • 管理生命周期
  • 聚合工程

 在启动时要将依赖的模块通过父工程pom中的mvn install将子工程中pom文件中有

<packaging>jar</packaging>

打成jar包,再进行启动类启动 

父工程pom文件中

<packaging>pom</packaging>
子工程模块
<modules>
    <module>common</module>
    <module>beans</module>
    <module>mapper</module>
    <module>service</module>
    <module>api</module>
</modules>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值