您好,我面临着Eclipse中的以下错误问题,请帮助解决这个问题。
错误信息
- 无法解析类型org.springframework.beans.BeansException。它是从必需的.class文件间接引用的 *
我导入了jar文件(org.springframework.context-3.0.4.RELEASE),即使在那时我也面临这个问题。
参见下面的代码(其中我在ApplicationContext appCtx = new ClassPathXmlApplicationContext(“applicationContext.xml”)行得到问题;)
package com.csp.test.document;
import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.csp.model.Document;
import com.csp.service.DocumentService;
public class DocumentTest {
@Test
public void testGetDocument() {
ApplicationContext appCtx = new ClassPathXmlApplicationContext(
"applicationContext.xml");
DocumentService documentService = (DocumentService) appCtx
.getBean("documentService");
Document doc = documentService.getDocument(1);
String status = null;
if (doc != null) {
status = documentService.saveDocument(doc);
} else {
System.out.println("error in retreiving document");
}
assertEquals("Success Status", "SUCCESS", status);
}
}
字符串
6条答案
按热度按时间uwopmtnx1#
如果你没有使用maven(或任何其他依赖管理工具),你应该手动添加
spring-context
依赖,它们是spring-beans
,spring-core
,spring-aop
和spring-expression
,当然它们每个都有自己的依赖(传递依赖)。顺便说一下,BeansException
是spring-beans
模块的一部分imzjd6km2#
您可能缺少org.springframework.beans-3.0.4.RELEASE jar
vsnjm48y3#
是的,我已经设法解决了这个问题……我使用以下模式:程序和结果没有错误
版本:3.0.4.RELEASE
然后选择-> Maven-> Update Project
z6psavjg4#
字符串
cygmwpex5#
出现错误是因为您缺少Spring Beans依赖项。如果您使用的是Maven,请将SpringBeans依赖项添加到pom.xml文件中。
举例如下:
字符串
您可以从Maven Repository网站搜索Spring Beans的最新版本:https://mvnrepository.com/
ogsagwnx6#
右键单击您的项目>选择Maven>更新项目>选择项目名称>确定
这解决了我的错误。