2

My code looks like below:

import org.apache.catalina.core.ApplicationContext; 
import org.springframework.context.support.ClassPathXmlApplicationContext;

public static void main(String args[]) {
    ApplicationContext context = 
        new ClassPathXmlApplicationContext("spring_conf.xml");
}

why i am getting this error ?

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
Type mismatch: cannot convert from ClassPathXmlApplicationContext to ApplicationContext

at root.Main.main(Main.java:11)

Anything i am missing or doing wrong?

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
Hossein Boka
  • 277
  • 2
  • 7
  • 15

3 Answers3

8

Change your first Spring import to:

import org.springframework.context.ApplicationContext

This is the correct interface that ClassPathXmlApplicationContext implements.

Reimeus
  • 158,255
  • 15
  • 216
  • 276
5

The import org.apache.catalina.core.ApplicationContext is incorrect, it must be

org.springframework.context.ApplicationContext
ndeverge
  • 21,378
  • 4
  • 56
  • 85
0

Here is a simple solution.

Replace import statement org.apache.catalina.core.ApplicationContext; with the below import statement:

import org.springframework.context.ApplicationContext;

Works for sure, if not Let me know.

Nikolay Mihaylov
  • 3,868
  • 8
  • 27
  • 32
Raghu
  • 1