用mybatis搞了一个访问数据库的maven工程,然后打成jar包,在另外一个工程上用反射调用的方式访问其中的方法。在myeclipse上没有问题可以访问到,但是在idea上出现问题。
public class Test1 {
public static void main(String[] args) throws Exception {
File file=new File("D:/class/ML/backer.jar");
URL url=file.toURI().toURL();
ClassLoader loader=new URLClassLoader(new URL[]{url});
try{
Class> cls=loader.loadClass("com.backer.controller.DataSource");
Object obj=cls.newInstance();
Method method=cls.getMethod("getAllData", String.class);
ResponseBean rb=(ResponseBean) method.invoke(obj, new String("admin"));
System.out.println(rb.getRetMap());
}catch(Exception e){
}
}
}
此代码在myeclipse上运行是没有错误的
然后放在idea上运行则出现以下错误
Caused by: org.apache.ibatis.binding.BindingException: Type interface com.sunyard.backer.dao.AlgorithmDataMapper is not known to the MapperRegistry.
at org.apache.ibatis.binding.MapperRegistry.getMapper(MapperRegistry.java:47)
at org.apache.ibatis.session.Configuration.getMapper(Configuration.java:745)
at org.apache.ibatis.session.defaults.DefaultSqlSession.getMapper(DefaultSqlSession.java:292)
at com.backer.controller.DataSource.getAllData(DataSource.java:31)
... 5 more
说我写的mapper没有被注册到mybatis里。这个应该不是代码的问题,网上有提到idea和myeclipse的某些差异,应该是某些开发工具的设置?
另外jar是在myeclipse中开发的,也是在myeclipse中打的包。
请教应该如何设置,或者有什么办法?