gpt4 book ai didi

java - 线程中的Spring异常 "main"java.lang.NoSuchMethodError : org. springframework.util.ReflectionUtils.clearCache()V

转载 作者:行者123 更新时间:2023-12-02 10:36:01 29 4
gpt4 key购买 nike

我是 Spring 新手,我正在尝试使用 Spring 容器构造对象,该容器将解析我的 XML 文件,所以我有一个 .xml 和两个 .java类。

Spring版本5.1.0

我正在寻找类似的解决方案,但有些是 Maven 解决方案,不适用于 Spring。

  1. employeeBeanFile.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd">

    <bean id="emp" class="co.bin.rito.Employee">
    <property name="eid" value="143529" />
    <property name="ename" value="Rito Sarkar" />
    <property name="eaddress" value="Tower Two Magarpatta, S5-458" />
    </bean>

  2. Employee.java

    public class Employee {
    // this contains attributes
    // constructor and methods
    // and set, get and toString() function
    }
  3. Client.java

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

    public class Client {

    public static void main(String[] args) {
    // Spring way | IOC (Inversion of control)
    ApplicationContext context = new ClassPathXmlApplicationContext("employeeBeanFile.xml");
    Employee e = (Employee) context.getBean("emp");
    System.out.println("Employee one details: " + e);
    ((AbstractApplicationContext) context).close();
    }}

使用此代码我收到以下错误

Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.util.ReflectionUtils.clearCache()V
at org.springframework.context.support.AbstractApplicationContext.resetCommonCaches(AbstractApplicationContext.java:910)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:573)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85)
at co.bin.rito.Client.main(Client.java:11)

最佳答案

出现此错误是由于 Spring 中的 jar 版本不同。请在您的 pom 中使用正确的 jar 依赖项。还要确保您的构建路径中没有包含其他版本的 jar。

关于java - 线程中的Spring异常 "main"java.lang.NoSuchMethodError : org. springframework.util.ReflectionUtils.clearCache()V,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53286485/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com