简体   繁体   中英

Spring Exception in thread “main” java.lang.NoSuchMethodError: org.springframework.util.ReflectionUtils.clearCache()V

I am new in spring and I am trying to construct the object using Spring Container which shall parse my XML file, so I have one .xml and two .java class.

Spring version 5.1.0

I was looking into similar solution but some are maven solution not for 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(); }} 

With this code i am getting below error

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)

This error occurs due the jars from different version in Spring. please use the correct jars dependency in your pom . Also make sure you are not including the other version of jars in your build path .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM