【问题标题】:The type org.springframework.beans.BeansException cannot be resolved. It is indirectly referenced from required .class filesorg.springframework.beans.BeansException 类型无法解析。它是从所需的 .class 文件中间接引用的
【发布时间】:2015-02-10 02:11:55
【问题描述】:

您好,在 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);

        }

    }

【问题讨论】:

  • 这个jar需要存在于依赖中。

标签: java javascript eclipse spring swing


【解决方案1】:

发生错误是因为您缺少 Spring Beans 依赖项。如果您使用的是 Maven,请将 Spring Beans 依赖项添加到您的 pom.xml 文件中。

一个例子如下:

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

您可以从 Maven 存储库网站搜索最新版本的 Spring Beans:https://mvnrepository.com/

【讨论】:

    【解决方案2】:
    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>*
    

    【讨论】:

      【解决方案3】:

      是的,我已经设法解决了这个问题....我使用以下模式:程序和结果没有错误

      版本: 3.0.4.发布

      然后选择-> Maven-> 更新项目

      【讨论】:

      • 欢迎来到 StackOverflow!环顾四周,这是英文网站。目前,我已将这篇文章翻译成英文。请用英文发布您的问题、答案和 cmets。
      【解决方案4】:

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

      【讨论】:

      • 谢谢 :) 正如你所说,我已经下载(spring-beans-3.1.xsd 下载)jar,它对我有用......
      • 欢迎您。为了更好的依赖管理,我推荐使用 maven
      • 如果您是 maven 用户,请升级您的版本 >= 4.0.0
      • 好的,现在我看到了这个异常是什么时候引发的,你能给出确切的原因,比如BeansException
      【解决方案5】:

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

      【讨论】:

      • 没错!这个 jar 需要存在于依赖项中。
      猜你喜欢
      • 1970-01-01
      • 2017-10-05
      • 2013-05-14
      • 2017-02-26
      • 2016-10-31
      • 2016-02-20
      • 2019-01-26
      • 2012-04-30
      • 2014-10-15
      相关资源
      最近更新 更多