ActiveRecordPlugin报错始终找不到原因在哪里

2018-08-27 17:58:11

[ERROR]-[Thread: main]-[com.jfinal.core.Config.startPlugins()]: Plugin start error: com.jfinal.plugin.activerecord.ActiveRecordPlugin. 

File not found : E:\workspaces\waiter\file:\E:\workspaces\waiter\src\main\webapp\WEB-INF\lib\alipay-sdk-java20180309170622.jar!/_user.sql

java.lang.RuntimeException: File not found : E:\workspaces\waiter\file:\E:\workspaces\waiter\src\main\webapp\WEB-INF\lib\alipay-sdk-java20180309170622.jar!/_user.sql

at com.jfinal.template.source.FileSource.getContent(FileSource.java:70)

at com.jfinal.template.Engine.buildTemplateBySourceFactory(Engine.java:153)

at com.jfinal.template.Engine.getTemplate(Engine.java:138)

at com.jfinal.plugin.activerecord.sql.SqlKit.parseSqlTemplate(SqlKit.java:92)

at com.jfinal.plugin.activerecord.ActiveRecordPlugin.start(ActiveRecordPlugin.java:224)

at com.jfinal.core.Config.startPlugins(Config.java:107)

at com.jfinal.core.Config.configJFinal(Config.java:51)

at com.jfinal.core.JFinal.init(JFinal.java:63)

at com.jfinal.core.JFinalFilter.init(JFinalFilter.java:49)

at org.eclipse.jetty.servlet.FilterHolder.doStart(FilterHolder.java:119)

at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)

at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:724)

at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:265)

at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)

at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:706)

at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:492)

at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)

at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)

at org.eclipse.jetty.server.Server.doStart(Server.java:277)

at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)

at com.jfinal.server.JettyServerForIDEA.doStart(JettyServerForIDEA.java:133)

at com.jfinal.server.JettyServerForIDEA.start(JettyServerForIDEA.java:72)

at com.jfinal.core.JFinal.start(JFinal.java:174)

at com.dlhz.common.Start.main(Start.java:14)


2018-08-27 17:58:11

[ERROR]-[Thread: main]-[com.jfinal.kit.LogKit.error()]: Plugin start error: com.jfinal.plugin.activerecord.ActiveRecordPlugin. 

File not found : E:\workspaces\waiter\file:\E:\workspaces\waiter\src\main\webapp\WEB-INF\lib\alipay-sdk-java20180309170622.jar!/_user.sql

java.lang.RuntimeException: Plugin start error: com.jfinal.plugin.activerecord.ActiveRecordPlugin. 

File not found : E:\workspaces\waiter\file:\E:\workspaces\waiter\src\main\webapp\WEB-INF\lib\alipay-sdk-java20180309170622.jar!/_user.sql

at com.jfinal.core.Config.startPlugins(Config.java:116)

at com.jfinal.core.Config.configJFinal(Config.java:51)

at com.jfinal.core.JFinal.init(JFinal.java:63)

at com.jfinal.core.JFinalFilter.init(JFinalFilter.java:49)

at org.eclipse.jetty.servlet.FilterHolder.doStart(FilterHolder.java:119)

at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)

at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:724)

at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:265)

at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)

at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:706)

at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:492)

at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)

at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)

at org.eclipse.jetty.server.Server.doStart(Server.java:277)

at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)

at com.jfinal.server.JettyServerForIDEA.doStart(JettyServerForIDEA.java:133)

at com.jfinal.server.JettyServerForIDEA.start(JettyServerForIDEA.java:72)

at com.jfinal.core.JFinal.start(JFinal.java:174)

at com.dlhz.common.Start.main(Start.java:14)

Caused by: java.lang.RuntimeException: File not found : E:\workspaces\waiter\file:\E:\workspaces\waiter\src\main\webapp\WEB-INF\lib\alipay-sdk-java20180309170622.jar!/_user.sql

at com.jfinal.template.source.FileSource.getContent(FileSource.java:70)

at com.jfinal.template.Engine.buildTemplateBySourceFactory(Engine.java:153)

at com.jfinal.template.Engine.getTemplate(Engine.java:138)

at com.jfinal.plugin.activerecord.sql.SqlKit.parseSqlTemplate(SqlKit.java:92)

at com.jfinal.plugin.activerecord.ActiveRecordPlugin.start(ActiveRecordPlugin.java:224)

at com.jfinal.core.Config.startPlugins(Config.java:107)

... 18 more





下面是我的配置信息

注释掉下main红色部分项目就能启动,去掉注释就启动报上面的错



public class ProjectConfig extends JFinalConfig {

/**

* 配置常量

*/

@Override

public void configConstant(Constants me) {

PropKit.use("projectConfig.properties");

me.setDevMode(PropKit.getBoolean("devMode", true));// 是否启用开发模式

me.setJsonFactory(MixedJsonFactory.me());// 由于jfinal自身对json转换的不足,使用fastjson对json转对象做补充

me.setError404View("/error/404.html");

me.setErrorView(405, "/error/405.html");

}


@Override

public void configEngine(Engine me) {

// TODO Auto-generated method stub

}


@Override

public void configHandler(Handlers me) {

me.add(new HtmlFakeStaticHandler(".do"));

}


@Override

public void configInterceptor(Interceptors me) {

me.add(new SessionInViewInterceptor());// jfinal template

// engine,设计为可以在任何 java

// 环境中运行,所以默认不会知道,session

// 的存在,需要添加session拦截器

me.add(new AllowCrossDomainInterceptor());

}


@Override

public void configPlugin(Plugins me) {

/**

* 配置数据源 开始

*/

DruidPlugin druidPlugin = createDruidPlugin();

me.add(druidPlugin);

ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);

arp.setTransactionLevel(Connection.TRANSACTION_READ_COMMITTED);

_MappingSqlKit.mapping(arp);

_MappingKit.mapping(arp);

PropKit.use("projectConfig.properties");

if (PropKit.getBoolean("devMode", false)) {

arp.setShowSql(true);

}

me.add(arp);

/**

* 配置redis

*/

RedisPlugin rp = null;

if (StrKit.notBlank(PropKit.use("redis.properties").get("password"))) {

rp = new RedisPlugin(PropKit.use("redis.properties").get("topic"),

PropKit.use("redis.properties").get("host"), PropKit.use("redis.properties").getInt("port"),

PropKit.use("redis.properties").get("password"));

} else {

rp = new RedisPlugin(PropKit.use("redis.properties").get("topic"),

PropKit.use("redis.properties").get("host"), PropKit.use("redis.properties").getInt("port"));

}

me.add(rp);

/**

* 配置定时任务

*/

QuartzPlugin quartzPlugin = new QuartzPlugin();

quartzPlugin.setJobs("jobs.properties");

me.add(quartzPlugin);

}


@Override

public void configRoute(Routes me) {

me.add(new ManagerLoginRoute());

me.add(new ManagerRoute());

me.add(new MerchantLoginRoute());

me.add(new MerchantRoute());

me.add(new MerchantAppLoginRoute());

me.add(new MerchantAppRoute());

me.add(new AgentAppLoginRoute());

me.add(new AgentAppRoute());

me.add(new DataScreenRoote());

me.add(new WeiXinQrRoute());

me.add(new WeiXinQrLoginRoute());

me.add(new QrAfterMealLoginRoute());

me.add(new QrAfterMealRoute());

me.add("/commmon/upload", UploadController.class);

me.add("/common/address",AddressController.class);

me.add("/common/merchantSuperJurisdiction",MerchantSuperJurisdictionController.class);

me.add("/test",TestController.class);

me.add("/pay/zfb",ZfxController.class);

me.add("/xingye/pay/staticCode",XingYeJIntaiController.class);

me.add("/merchant/weixin/weixin",WeixinController.class); // 微信回调

me.add("/merchant/getpassword", GetPasswordOfBackWindow.class);

//me.add("/merchant/qr/weixin",WeiXinController.class); // 微信登录路由

}


/*

* 数据库连接池配置

*/

public static DruidPlugin createDruidPlugin() {

Prop p = PropKit.use("mysqlConfig.properties");

return new DruidPlugin(p.get("jdbcUrl"), p.get("user"), p.get("password"));

}


@Override

public void afterJFinalStart() {

try {

MsgType.wsstart = new MyWsStart(12316, new MyMsgHandler());

MsgType.wsstart.start();

} catch (IOException e) {

System.out.println("websocket已启动了");

}

}


@Override

public void beforeJFinalStop() {

MsgType.wsstart.stop();

}

}

_MappingSqlKit.mapping(arp)文件内容:

public static void mapping(ActiveRecordPlugin arp) {

arp.setBaseSqlTemplatePath(PathKit.getRootClassPath());

arp.addSqlTemplate("_user.sql");

arp.addSqlTemplate("_managerLog.sql");

arp.addSqlTemplate("_userManager.sql");

arp.addSqlTemplate("_managerMenu.sql");

arp.addSqlTemplate("_managerRole.sql");

arp.addSqlTemplate("_managerMenuRole.sql");

arp.addSqlTemplate("_agent.sql");

arp.addSqlTemplate("_provinces.sql");

arp.addSqlTemplate("_citis.sql");

arp.addSqlTemplate("_areas.sql");

arp.addSqlTemplate("_merchant.sql");

arp.addSqlTemplate("_merchantAdmin.sql");

arp.addSqlTemplate("_merchantRoleMenu.sql");

arp.addSqlTemplate("_merchantMenu.sql");

arp.addSqlTemplate("_merchantRole.sql");

arp.addSqlTemplate("_kitchenPrinter.sql");

arp.addSqlTemplate("_merchantLog.sql");

arp.addSqlTemplate("_dishes.sql");

arp.addSqlTemplate("_tableClassification.sql");

arp.addSqlTemplate("_table.sql");

arp.addSqlTemplate("_commodityGallery.sql");

arp.addSqlTemplate("_food.sql");

arp.addSqlTemplate("_orderForm.sql");

arp.addSqlTemplate("_orderDetail.sql");

arp.addSqlTemplate("_orderLog.sql");

arp.addSqlTemplate("_book.sql");

arp.addSqlTemplate("_payment.sql");

arp.addSqlTemplate("_orderPaytype.sql");

arp.addSqlTemplate("_userCard.sql");

arp.addSqlTemplate("_cardBalanceRecord.sql");

arp.addSqlTemplate("_cardIntegralRecord.sql");

arp.addSqlTemplate("_print_template.sql");

arp.addSqlTemplate("_turnoverRecord.sql");

arp.addSqlTemplate("_agentLog.sql");

arp.addSqlTemplate("_agentProfitRecord.sql");

arp.addSqlTemplate("_systemBasic.sql");

arp.addSqlTemplate("_agentPresentRecord.sql");

arp.addSqlTemplate("_notice.sql");

arp.addSqlTemplate("_callRecord.sql");

arp.addSqlTemplate("_callClassification.sql");

arp.addSqlTemplate("_merchantNotice.sql");

arp.addSqlTemplate("_merchantUpdate.sql");

arp.addSqlTemplate("_turnoverRechargeMethod.sql");

arp.addSqlTemplate("_turnoverRechargeRecord.sql");

arp.addSqlTemplate("_msgrecord.sql");

arp.addSqlTemplate("_usercardclassification.sql");

arp.addSqlTemplate("_usercardAccounting.sql");

arp.addSqlTemplate("_merchantappMenu.sql");

arp.addSqlTemplate("_merchantappRoleMenu.sql");

arp.addSqlTemplate("_materielStock.sql");

arp.addSqlTemplate("_materiel.sql");

arp.addSqlTemplate("_materielInstockl.sql");

arp.addSqlTemplate("_materielOutstock.sql");

arp.addSqlTemplate("_merchantClassify.sql"); 

arp.addSqlTemplate("_orderDiscount.sql"); 

arp.addSqlTemplate("_orderRefund.sql"); 

arp.addSqlTemplate("_merchantUserNo.sql"); 

arp.addSqlTemplate("_kitchenPrinterClass.sql"); 

arp.addSqlTemplate("_merchantBackMerchant.sql"); 

}



评论区

CrazyZH

2018-08-27 18:10

换了个工具就这样了 而且在原来的工具里面还能运行

CrazyZH

2018-08-27 18:26

上面的PathKit.getRootClassPath()打印出来是:E:\workspaces\waiter\file:\E:\workspaces\waiter\src\main\webapp\WEB-INF\lib\alipay-sdk-java20180309170622.jar!感觉错误就在这里 大神帮帮忙

JFinal

2018-08-27 18:37

@CrazyZH 你的程序在某处配置了
arp.getEngine().setSourceFactory(new ClassPathSourceFactory());

所以,引擎去 jar 包以及 class path 下面去寻找 sql 模板了,造成模板找不到,但从你上面给出的代码中看不出来你的配置,肯定是某个地方配置了,或者是自动编译没有打开

JFinal

2018-08-27 18:39

你的异常给的不全,异常中应该包含一个 ClassPathSource,是这个类在读文件的时候找不到

JFinal

2018-08-27 18:42

这里补充一个重要内容:如果你配置了 ClassPathSourceFactory,那么会在 linux 文件句柄打开过多,不能及时关闭

解决这个问题看一下这里:
http://www.jfinal.com/share/979

jfinal 3.5 已经改进过这里,此外,如果不配置 ClassPathSourceFactory 就不需要理会

CrazyZH

2018-08-28 11:05

@JFinal 没有arp.getEngine().setSourceFactory(new ClassPathSourceFactory());这个而且之前的都是好的,换了个工具就不行了,自动编译在哪里设置

JFinal

2018-08-28 11:21

PathKit.getRootClassPath()打印出来是:E:\workspaces\waiter\file:\E:\workspaces\waiter\src\main\webapp\WEB-INF\lib\alipay-sdk-java20180309170622.jar!

错误就是这里了,正常情况是项目的 webapp/WEB-INF/classes 下面,如果是 maven 项目则是 target/classes 下面

应该是你的项目配置有问题,解决办法有两个:
1:如果是 maven 项目,则保留 src 目录以及 pom.xml 文件,删掉所有的东西,重新当成 maven 项目导入一次,让 eclipse 重新帮你生成那些额外的配置文件

2:如果不是 maven 项目,按照文档来配置一下 Default output folder 目录即可

CrazyZH

2018-08-28 11:23

@JFinal 好的 谢谢波总

JFinal

2018-08-28 11:34

@CrazyZH 简单说就是要让 PathKit.getRootClassPath() 输出的目录确实是指向了你的 sql 文件输出的目录,你的 sql 文件会被自动编译到 classes 目录下面,这个目录下面还有其它的被编译成 .class 的文件

热门反馈

扫码入社