eclipse 无法解析类型org.springframework.beans.BeansException,它是从必需的.class文件间接引用的

myzjeezk  于 2023-08-04  发布在  Eclipse
关注(0)|答案(6)|浏览(152)

您好,我面临着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);

        }

    }

字符串

uwopmtnx

uwopmtnx1#

如果你没有使用maven(或任何其他依赖管理工具),你应该手动添加spring-context依赖,它们是spring-beansspring-corespring-aopspring-expression,当然它们每个都有自己的依赖(传递依赖)。顺便说一下,BeansExceptionspring-beans模块的一部分

imzjd6km

imzjd6km2#

您可能缺少org.springframework.beans-3.0.4.RELEASE jar

vsnjm48y

vsnjm48y3#

是的,我已经设法解决了这个问题……我使用以下模式:程序和结果没有错误
版本:3.0.4.RELEASE
然后选择-> Maven-> Update Project

z6psavjg

z6psavjg4#

I have problems with *org.springframework.context.EnvironmentAware*
Adding this dependency in pom from maven repository solve my problem.

*<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
    <version>5.0.3.RELEASE</version>
</dependency>*

字符串

cygmwpex

cygmwpex5#

出现错误是因为您缺少Spring Beans依赖项。如果您使用的是Maven,请将SpringBeans依赖项添加到pom.xml文件中。
举例如下:

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-beans</artifactId>
  <version>5.3.5</version>
</dependency>

字符串
您可以从Maven Repository网站搜索Spring Beans的最新版本:https://mvnrepository.com/

ogsagwnx

ogsagwnx6#

右键单击您的项目>选择Maven>更新项目>选择项目名称>确定
这解决了我的错误。

相关问题