0

我是 Spring 新手,目前正在尝试ProSpring3 书中的以下Hello World 示例:

package com.tutorials.prospring3.ch2;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

    public class HelloWorldSpringDI {
        public static void main(String[] args) {
            // Initialize Spring ApplicationContext
            ApplicationContext ctx = new ClassPathXmlApplicationContext(
                    "META-INF/spring/app-context.xml");
            MessageRenderer mr = ctx.getBean("renderer", MessageRenderer.class);
            mr.render();
        }
    }

ClassPathXmlApplicationContext 实例化被标记为以下错误:“构造函数 ClassPathXmlApplicationContext(String) 引用缺少的类型 BeansException”

此外,在运行应用程序时,IDE 会显示构建路径问题: “Archive for required library: 'C:/Users/Admin/.m2/repository/org/springframework/spring-beans/3.0.6.RELEASE/spring-项目 'ch2' 中的 beans-3.0.6.RELEASE.jar' 无法读取或不是有效的 ZIP 文件”

由于 spring-beans.jar(BeansException 类所属的)是我的Maven 依赖项的一部分,我想知道这是怎么发生的。

STS 截图

有没有人建议如何解决这个问题?

提前致谢!

乔纳斯

4

6 回答 6

4

尝试C:/Users/Admin/.m2/repository/org/springframework/spring-beans/3.0.6.RELEASE/spring-beans-3.0.6.RELEASE.jar使用 WinZip 等应用程序打开存档。如果该应用程序指示存档也已损坏,则应将其删除并重试。(删除整个C:/Users/Admin/.m2/repository/org/springframework/spring-beans/3.0.6.RELEASE目录及其所有内容)。在项目的下一次构建中,将再次下载存档。如果它仍然不起作用并且您正在连接到本地存储库,您应该联系管理员。

于 2013-09-13T10:49:32.457 回答
3

我知道你的问题已经过时了,我只是想帮助遇到同样问题的人,因为我遇到了同样的问题并完成了它。这很容易,只需将 org.springframework.beans.jar 添加到您的项目中。

于 2016-06-13T09:01:40.460 回答
1

看起来项目的类路径中缺少依赖项。解决它

Right click on your project
Navigate to **Maven**
Click on **Update project**

如果它不能解决这个问题,那么

去路径

C:/Users/Admin/.m2/repository/org/springframework/ 并删除名为spring-beans

Now again Right click on your project
Navigate to **Maven**
Click on **Update project**

它将更新/添加项目的孤立/缺失依赖项

于 2015-04-22T10:03:33.157 回答
0

两个原因:

  1. 问题可能出在损坏的 Spring JAR 上。删除现有的 Spring 依赖项从以下位置添加依赖项:http: //mvnrepository.com/artifact/org.springframework/spring-beans/5.0.0.M5 它会解决问题。

2.对beans的间接依赖添加不够。

添加依赖项。

萨米尔·苏库马兰

于 2017-05-16T15:51:54.257 回答
0

转到 :C:\Users(user_name(or)admin_name).m2\repository\org\springframework

现在,删除 spring-beans 和 spring-expression 文件夹。

转到:Eclipse,然后通过右键单击项目 maven>更新项目来更新项目。Eclipse 将下载所需的文件。问题已解决 :-)

于 2017-08-22T06:46:18.417 回答
0

我在使用 Spring 的 4.2.2.RELEASE 版本时遇到了同样的问题,一旦我将其更改为 4.2.0.RELEASE,错误就消失了。我希望这对你的情况也有帮助。

于 2017-11-04T10:16:52.133 回答