![](/img/trans.png)
[英]spring java.lang.ClassNotFoundException: org.springframework.context.ApplicationContext
[英]java.lang.ClassNotFoundException: org.springframework.context.ApplicationContext
嘗試創建時出現此異常
應用上下文應用上下文;
我有
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.1.7.RELEASE</version>
</dependency>
在我的 servlet 中也有這個
導入 org.springframework.context.ApplicationContext;
在我的pom.xml
中,但仍然收到此消息。 我試過mvn.clean
你有沒有嘗試過:
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
您可以通過 2 種方式創建ApplicationContext
1) 基於 XML:
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
這里beans.xml
包含所有 bean 定義。
2)基於注釋:
ApplicationContext context = new AnnotationConfigApplicationContext(ApplicationConfiguration.class);
在這里, ApplicationConfiguration
使用@Configuration
注解進行注解。
另外,請確保類路徑包含所有 spring jars。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.