您好,我在 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);
}
}
最佳答案
如果你没有使用 maven(或任何其他依赖管理工具,就此而言),你应该手动添加 spring-context
依赖,它们是 spring-beans
、spring-core
、spring-aop
和spring-expression
,当然它们各自都有自己的依赖(Transitive Dependency)。顺便说一句,BeansException
是 spring-beans
模块的一部分
关于java - 无法解析类型 org.springframework.beans.BeansException。它是从所需的 .class 文件中间接引用的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27425472/