我正在尝试使用iBatis的桌面应用程序。但我得到了以下错误。无法在网上找到合适的解决方案。请任何人帮助我。
日志::
Exception in thread "main" java.lang.NoSuchMethodError: com.ibatis.common.beans.ClassInfo.setCacheEnabled(Z)V
at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser$3.process(SqlMapConfigParser.java:179)
at com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:112)
at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:75)
at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:93)
at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:63)
at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:51)
at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:86)
at com.ibatis.sqlmap.client.SqlMapClientBuilder.buildSqlMapClient(SqlMapClientBuilder.java:63)
at IbatisInsert.main(IbatisInsert.java:12)
Codes :: IbatisInsert.java
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import java.io.*;
import java.sql.SQLException;
import java.util.*;
public class IbatisInsert{
public static void main(String[] args)
throws IOException,SQLException{
Reader rd = Resources.getResourceAsReader("SqlMapConfig.xml");
SqlMapClient smc = SqlMapClientBuilder.buildSqlMapClient(rd);
/* This would insert one record in Employee table. */
System.out.println("Going to insert record.....");
Employee em = new Employee("Zara", "Ali", 5000);
smc.insert("Employee.insert", em);
System.out.println("Record Inserted Successfully ");
}
}
Employee.java
public class Employee {
private int id;
private String first_name;
private String last_name;
private int salary;
/* Define constructors for the Employee class. */
public Employee() {}
public Employee(String fname, String lname, int salary) {
this.setFirst_name(fname);
this.setLast_name(lname);
this.setSalary(salary);
}
public String getFirst_name() {
return first_name;
}
public void setFirst_name(String first_name) {
this.first_name = first_name;
}
public String getLast_name() {
return last_name;
}
public void setLast_name(String last_name) {
this.last_name = last_name;
}
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
} /* End of Employee */
我已将这两个类放在src下的默认包中。
答案 0 :(得分:1)
问题在于classloading / classpath。尝试在主类中使用此代码,并找出jar加载位置的路径。
您加载的jar可能是不正确的版本。
public static void main(String[] args) {
URLClassLoader classLoader = (URLClassLoader)IbatisInsert.class.getClassLoader();
System.out.println(Arrays.toString(classLoader.getURLs()));
}