1

Why I need to include spring-context in my new spring boot project to work ?

I have this in my pom.xml

 <dependency> 
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
  </dependency>
  <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
  </dependency> 

I can see inside spring-web dependency, the dependency spring-context

if I remove spring-context from my pom.xml, the application does not run.

Below is the error I get :

Exception encountered during context initialization - cancelling refresh attempt: 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'nameOfController'
Lazycoder-007
  • 1,055
  • 9
  • 19
Carlos Martinez
  • 335
  • 1
  • 9

2 Answers2

0

Do you see the spring-context to be provided with spring-web or really that it just depends on it? You might want to do yourself a favor and use the spring boot starter artefacts that actually come with all required dependencies and don't mark any of them as "provided".

In your case, it would be spring-boot-starter-web.

godsim
  • 181
  • 1
  • 9
0

When we go through the compile dependencies of spring-web , then spring-context is not included in the latest-version.

https://frontbackend.com/maven/artifact/org.springframework/spring-web/5.2.6.RELEASE

Though it was present in the previous versions.

https://frontbackend.com/maven/artifact/org.springframework/spring-web/4.3.20.RELEASE

Since, I cannot see the specific version that you'r adding to your pom.xml file, I am assuming it is getting the latest version, where the dependency of spring-context is not included in spring-web.

Also, the error stack trace that you have provided is very less and generic in nature, so it becomes difficult to debug your problem further, though I think it is a problem with version.

You can give the specific version in this way :

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>5.2.6.RELEASE</version>
</dependency>
Lazycoder-007
  • 1,055
  • 9
  • 19