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

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.