I am using a jar file developed by our developers, executing that Jar main method in Katalon studio is throwing error - java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.clearCache()V

May 12, 2020 2:26:47 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [app-context.xml]
2020-05-12 14:26:50.053 ERROR k.k.c.m.CustomKeywordDelegatingMetaClass - :x: java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.clearCache()V
2020-05-12 14:26:50.059 ERROR c.k.katalon.core.main.TestCaseExecutor - :x: Test Cases/CoreFeatures/Simulation/GrpcSimulation FAILED.
Reason:
org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.clearCache()V
at com.osi.cs.businesskeywords.GrpcSimulationKeywords.invokeMethod(GrpcSimulationKeywords.groovy)
at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:50)
at GrpcSimulation.run(GrpcSimulation:18)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1589273803135.run(TempTestCase1589273803135.groovy:25)
Caused by: java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.clearCache()V
at org.springframework.context.support.AbstractApplicationContext.resetCommonCaches(AbstractApplicationContext.java:911)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:573)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:144)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:85)
at com.osi.cis.simulator.SimulatorApp.(SimulatorApp.java:16)
at com.osi.cs.businesskeywords.GrpcSimulationKeywords.GRPCSimulationProcess(GrpcSimulationKeywords.groovy:10)
… 14 more

hello,
how this custom .jar is imported to testscript?
custom .jar should be in Drivers folder and then KS restart will be in classpath

@Timo_Kuisma1 Yes, Custom jar was included in Drivers folder… Am able to call a method in Jar file(I don’t have any errors calling a Method in Jar), While executing Spring Framework exception has been thrown

Does your jar includes the class org.springframework.core.annotation.AnnotationUtils ?
Maybe not. This class would be included in the jar provided by the Spring Framework project. You need to find out necessary jar files from the Spring Framework project (Maven Central?), download them and deploy them into the Drivers folder as well.

Googling gave me this reference:

This post says this problem depends on the specific version of Spring Framework you put into the classpath.

In other words, you need to find which exact version of Spring Framework jar to put into the Driver folder of KS project. If you put wrong version of Spring Framework, the problem may not be solved.

I mean you have got a new problem: how can you resolve the external dependencies for your Custom Keywords?

The Spring Framework project provides a lot of jars which are dependent each other. When your keyword requires a single jar of Spring Framework, the jar may depends other jars which have their own dependencies … it is very hard (I would say impossible) to find out manually the complete list of dependent jars which your Custom Keyword depends directory and indirectly upon.

Please have a look at this previous post of mine:

This post will show you how I resolved external dependencies (AWS CLI) needed by my Custom keyword.

I have provided Spring Framework version in External Libraries(Version as mentioned for deveoping Jar), will try providing AnnotationUtils jar…

Below I mentioned the gradle plugin info:
I mentioned the Spring Framework version developers has used… But yet I am getting same exception.

plugins {
id ‘java’
id “com.katalon.gradle-plugin” version “0.0.7”
id ‘java-library’
}

repositories {
jcenter()
mavenCentral()
flatDir {
dirs ‘Libs’
}
}

dependencies {
compile group: ‘com.microsoft.sqlserver’, name: ‘mssql-jdbc’, version: ‘8.2.2.jre13’
compile files(‘Libs/grpc-simulator.jar’)
compile group: ‘org.springframework’, name: ‘spring-core’, version: ‘4.3.2.RELEASE’
compile group: ‘org.springframework’, name: ‘spring-context’, version: ‘4.3.2.RELEASE’
}

sourceSets{
test.java.srcDir ‘Test Cases’
}

I opened a Keyword file & tried importing AnnotationUtils, am getting 2 suggestions.

Can you please share Katalon Studio used Spring Framework version…

Am able to execute same code in eclipse - just executing as a Java Application (Included main in Keyword)… In Katalon Studio , am not able to execute it… Its throwing above mentioned exception

On my Mac, in the Applications/Katalon Studio.app/Contents/Eclipse/plugins/ directory, I could see all the external jars which Katalon Studio bundles. In the directory I do not find any org.springramework products. Therefore I believe that Katalon Studio does not depend on and does not bundle the jars of Spring Framework. Therefore you need to setup the dependencies properly yourself.

Please check if you have all required jar files in the Drivers folder of your project. Please share us the list of Drivers folder:

$ cd $yourProjectDir
$ ls -la

Do you find katalon_generated_org.springframework.spring-core.4.3.2.RELEASE.jar in that directory?

I suppose you don’t. That’s the reason why you can not import the AnnotationUtil class.

Did you execute a commandline command gradle katalonCopyDependencies?

$ cd $yourProjectDir
$ ./gradlew katalonCopyDependencies

It is not enough writing the build.gradle file. You need to execute the command.

The katalonCopyDependencies task does the following

  1. download the jar files from the Maven repository into your local maven repository ~/.m2
  2. copy the jars from the local maven repository into the Drivers directory of your Katalon project while renaming the jar files slightly: prepend a prefix of katalon_generated_.

I ran Gradle KatalonCopyDependencies cmd, Please find the Drivers folder related info below

Okay… I have seen that I didn’t see any spring framework dependencies.

In .classpath available in project directory - Spring Framework latest version(spring-context-5.1.0.RELEASE.jar) was included… Can I exclude this default jar invoked by Katalon in build.gradle…

Do you think the version mismatch is the cause of your problem? well, sad to hear that. This looks the worst case.

Why not you try a risky surgery? — remove manually the unwanted spring-context-5.1.0.RELEASE.jar from the configuration/resources/lib/, stop and restart KS, and see what happens?

One idea would be, ask your developer to modify the custom keywords to work with the Sprig Framework version which is bundled in KS.

Previously mentioned issue got resolved by deleting spring jar file

Came accress this exception now:
Reason:
java.lang.NoSuchMethodError: org.json.JSONArray.forEach(Ljava/util/function/Consumer;)V
at com.osi.cis.client.DataBuilder.getMetadataMessage(DataBuilder.java:64)
at com.osi.cis.simulator.CISGrpcClientSimulator.sendImage(CISGrpcClientSimulator.java:80)
at com.osi.cis.simulator.SimulatorApp.runSimulator(SimulatorApp.java:40)
at com.osi.cis.simulator.SimulatorApp$runSimulator.call(Unknown Source)
at simulationprocess.run(simulationprocess:5)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1589353990511.run(TempTestCase1589353990511.groovy:25)