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>