Hossein Boka
Hossein Boka

Reputation: 386

Type Mismatch - why i am getting this error?

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?

Upvotes: 2

Views: 3568

Answers (3)

Reimeus
Reimeus

Reputation: 159874

Change your first Spring import to:

import org.springframework.context.ApplicationContext

This is the correct interface that ClassPathXmlApplicationContext implements.

Upvotes: 8

Raghu
Raghu

Reputation: 1

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.

Upvotes: 0

ndeverge
ndeverge

Reputation: 21564

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

org.springframework.context.ApplicationContext

Upvotes: 5

Related Questions