0

I get this exception when tried to create

ApplicationContext applicationContext;

I have

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

also have this in my servlet

import org.springframework.context.ApplicationContext;

in my pom.xml, but still getting this msg. I tried mvn.clean

Dushyant Tankariya
  • 1,432
  • 3
  • 11
  • 17
T.Sham
  • 1
  • 1
  • 3

2 Answers2

1

You can create ApplicationContext by 2 ways

1) XML based:

ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");

Here beans.xml contains all the bean definitions.

2) Annotations based:

ApplicationContext context = new AnnotationConfigApplicationContext(ApplicationConfiguration.class);

Here, ApplicationConfiguration is annotated with @Configuration annotation.

Also, please make sure that classpath has all the spring jars.

AbhiN
  • 642
  • 4
  • 18
0

Have you tried:

package com.zoltanraffai;  
import org.springframework.core.io.ClassPathResource;  
import org.springframework.beans.factory.InitializingBean; 
import org.springframework.beans.factory.xml.XmlBeanFactory;

public class HelloWorldApp{ 
   public static void main(String[] args) { 
      ApplicationContext context=new ClassPathXmlApplicationContext("beans.xml"); 
      HelloWorld obj = (HelloWorld) context.getBean("helloWorld");    
      obj.getMessage();    
   }
}

https://dzone.com/articles/difference-between-beanfactory-and-applicationcont

Horatiu Jeflea
  • 7,256
  • 6
  • 38
  • 67