为什么我需要在新的spring boot项目中包含spring-context才能正常工作?
我的pom.xml里有这个
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency> 我可以看到在spring-web依赖中,依赖于spring-context
如果我从pom.xml中删除了spring-context,应用程序就不会运行。
下面是我得到的错误:
Exception encountered during context initialization - cancelling refresh attempt:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'nameOfController'发布于 2020-05-28 22:46:21
你认为spring-context是随spring-web一起提供的,还是真的依赖于它?您可能希望帮自己一个忙,使用spring boot starter工件,这些工件实际上附带了所有必需的依赖项,并且没有将它们中的任何一个标记为“提供的”。
在您的例子中,它应该是spring-boot-starter-web。
发布于 2020-05-29 00:45:26
当我们遍历spring-web的编译依赖项时,latest-version.中不包含spring-context
https://frontbackend.com/maven/artifact/org.springframework/spring-web/5.2.6.RELEASE
,尽管它在以前的版本中存在。
https://frontbackend.com/maven/artifact/org.springframework/spring-web/4.3.20.RELEASE
由于我看不到您要添加到pom.xml文件中的特定版本,因此我假设它获得的是最新版本,其中spring-web中不包含spring-context的依赖项。
此外,您提供的错误堆栈跟踪非常少,而且本质上是通用的,因此很难进一步调试您的问题,尽管我认为这是版本的问题。
您可以这样给出具体版本:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.2.6.RELEASE</version>
</dependency>https://stackoverflow.com/questions/62057104
复制相似问题