【问题标题】:Spring Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.util.ReflectionUtils.clearCache()V线程“主”java.lang.NoSuchMethodError 中的 Spring 异常:org.springframework.util.ReflectionUtils.clearCache()V
【发布时间】:2018-11-13 17:25:26
【问题描述】:

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

春季版 5.1.0

我正在研究类似的解决方案,但有些是不适合 spring 的 maven 解决方案。

  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)

【问题讨论】:

  • 你的 pom 对于 spring 依赖项是什么样的?
  • 如果您正在混合来自不同版本框架的 jar,在本例中为 Spring,则会发生此错误。检查你的依赖关系。

标签: java spring spring-mvc xml-parsing nsxmlnode


【解决方案1】:

这个错误是由于 Spring 中不同版本的 jars 而发生的。请在您的 pom 中使用正确的 jars 依赖项。还要确保你的构建路径中没有包含其他版本的 jar。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-18
    • 2018-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-08
    相关资源
    最近更新 更多