java.lang.ClassNotFoundException: org.springframework.expression.ParserContext Spring HelloWorld?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39122276/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 04:06:19  来源:igfitidea点击:

java.lang.ClassNotFoundException: org.springframework.expression.ParserContext Spring HelloWorld?

javaspringmaven

提问by Mahesha999

I have simple Spring HelloWorld program. Its contents are as follows:

我有简单的 Spring HelloWorld 程序。其内容如下:

enter image description here

在此处输入图片说明

pom.xml

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mahesha999.examples.spring</groupId>
    <artifactId>SpringExamples</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>       
    </dependencies>

</project>

eg1.xml

eg1.xml

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">

    <bean id="helloBean" class="com.mahesha999.examples.spring.eg1.HelloWorld">
        <property name="name" value="Mahesha999" />
    </bean>

</beans>

HelloWorld.java

你好世界

public class HelloWorld {
    private String name;

    public void setName(String name) {
        this.name = name;
    }

    public void printHello() {
        System.out.println("Spring  : Hello ! " + name);
    }
}

App.java

应用程序.java

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

public class App {
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("eg1.xml");

        HelloWorld obj = (HelloWorld) context.getBean("helloBean");
        obj.printHello();
    }
}

This gave me following error:

这给了我以下错误:

INFO: Loading XML bean definitions from class path resource [eg1.xml]
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/expression/ParserContext
    at org.springframework.context.support.AbstractApplicationContext.prepareBeanFactory(AbstractApplicationContext.java:628)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:516)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at com.mahesha999.examples.spring.eg1.App.main(App.java:8)
Caused by: java.lang.ClassNotFoundException: org.springframework.expression.ParserContext
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 5 more

When I changed spring version from 4.3.2 to 4.2.2 in pom.xml, it worked fine. Why is it so?

当我在 pom.xml 中将 spring 版本从 4.3.2 更改为 4.2.2 时,它工作正常。为什么会这样?

回答by Programming-Lover

I was also getting the same error and it got fixed after adding the spring-expression jar

我也遇到了同样的错误,在添加 spring-expression jar 后它得到了修复

回答by abaghel

I tested you code in eclipse and it is working fine with both 4.2.2.RELEASE and 4.3.2.RELEASE. It is printing below message. Can you please clean you build or run build from command prompt.

我在 eclipse 中测试了你的代码,它在 4.2.2.RELEASE 和 4.3.2.RELEASE 中都可以正常工作。它正在打印以下消息。您能否从命令提示符清理您的构建或运行构建。

Spring  : Hello ! Mahesha999

回答by Ragav

You will get this error only when there is no "spring- expression" lib.
solution 1: In case after adding spring-expression lib still exists then try adding new version of spring library.

只有当没有“spring-expression”库时,您才会收到此错误。
解决方案 1:如果添加 spring-expression 库后仍然存在,则尝试添加新版本的 spring 库。

solution 2: Delete your spring.xml file along with its packg and then create new package with spring.xml.

解决方案 2:删除 spring.xml 文件及其 packg,然后使用 spring.xml 创建新包。

回答by Avinash Khadsan

i have use spring 4.3.11 version

so add the bellow jar into lib folder

1. commons-logging-1.1.1.jar
2. servlet-api.jar
3. spring-aop-4.3.11.RELEASE.jar
4. spring-beans-4.3.11.RELEASE.jar
5. spring-context-4.3.11.RELEASE.jar
6.spring-core-4.3.11.RELEASE.jar
7. spring-expression-4.3.11.RELEASE.jar
8. spring-web-4.3.11.RELEASE.jar
9.spring-webmvc-4.3.11.RELEASE.jar

回答by Ravan

Solution : Add the "spring-expression-4.3.11.RELEASE.jar" in your project and the rebuild your project.

解决方案:在您的项目中添加“spring-expression-4.3.11.RELEASE.jar”并重建您的项目。