线程“主”中的Spring异常java.lang.NoSuchMethodError:org.springframework.util.ReflectionUtils.clearCache()V

时间:2018-11-13 17:25:27

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

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

春季版本5.1.0

我一直在寻找类似的解决方案,但有些不是春季的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)

1 个答案:

答案 0 :(得分:1)

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