我的项目root目录下pom文件添加了springboot的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.6.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
前端的目录下pom中添加了,要用到@restcontroller
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.6.3</version>
</dependency>
然后一堆包冲突,是不是我的做法有错误,还是版本问题?
spring-boot-dependencies 和 spring-boot-starter-web 并不会发生冲突,它们分别是 Spring Boot 提供的依赖管理和 Web Starter,可以在一个项目中同时使用。
spring-boot-dependencies 是一个 Maven BOM(Bill of Materials),包含了所有 Spring Boot 项目中使用的依赖的版本信息,可以通过继承该 BOM 来轻松管理版本。它是一个空的 Maven 项目,只包含一个 pom.xml 文件,用于统一管理 Spring Boot 的依赖版本号。您可以在自己的项目中添加 BOM 依赖,例如:
spring-boot-starter-web 则是 Spring Boot Web Starter,包含了一些常用的 Web 组件,比如 Spring MVC、Tomcat、Jackson 等。通过添加该依赖,可以快速构建基于 Spring MVC 的 Web 项目。您可以在 Maven 项目中添加如下依赖:
如果您在添加 spring-boot-starter-web 依赖时发生冲突,可能是由于您在项目中同时添加了其他的 Web 框架、Servlet 容器或者 Spring Boot 的其他 Starter,这些依赖会导致版本冲突。您可以使用 mvn dependency:tree 命令查看项目依赖树,找到冲突的依赖,并将其排除或者升级版本。