Skip to content
Advertisement

Can’t import org.springframework.context.ApplicationContext?

I just started learning Spring and I have problem importing Classes from Spring, please help! I tried almost everything what I found as a solutions, but it was a failure…

Error:

The import org.springframework.context.ApplicationContext cannot be resolved.

Here’s my code

import org.springframework.context.*; //I can import this
import org.springframework.context.ApplicationContext; //But I can't import this

or

import org.springframework.stereotype.*; //I can import this
import org.springframework.stereotype.Controller; //But I can't import this

this is my pom.xml

<?xml version="1.0" encoding="UTF-8"?>
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <packaging>jar</packaging>
  <groupId>helloworld</groupId>
  <artifactId>hello-world</artifactId>
  <modelVersion>4.0.0</modelVersion>
  <version>1.0</version>



  <dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.3.2.RELEASE</version>
    </dependency>
</dependencies>

</project>

Advertisement

Answer

ApplicationContext resides in that package.

In your IDE if you control click on the import statement it should show you which jar it is resolving to. If it isnt run mvn clean install which will build and pull dependencies you need

Your project may not be auto importing maven dependencies so it doesn’t yet resolve.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement