JFinal 升级到3.0之后,链接数据库报错。

把项目升级到3.0之后,使用XXConfig中的main方法启动项目时,出现如下错误:

2017-03-04 16:34:45[INFO]-[Thread: main]-[com.hm.astock.manage.config.ManageConfig.configPlugin()]: redis 连接信息.缓存名称: astock,主机:120.77.217.142,端口:6389

2017-03-04 16:34:45[INFO]-[Thread: main]-[com.hm.astock.manage.config.ManageConfig.configPlugin()]: 常用参数缓存插件

2017-03-04 16:34:47[ERROR]-[Thread: main]-[com.alibaba.druid.pool.DruidDataSource.init()]: init datasource error

java.sql.SQLException: java.lang.IllegalAccessError: class sun.reflect.GeneratedConstructorAccessor2 cannot access its superclass sun.reflect.ConstructorAccessorImpl

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:937)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:872)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:904)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:894)

at com.mysql.jdbc.Util.handleNewInstance(Util.java:418)

at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)

at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)

at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:148)

at com.alibaba.druid.filter.FilterAdapter.connection_connect(FilterAdapter.java:786)

at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:142)

at com.alibaba.druid.filter.stat.StatFilter.connection_connect(StatFilter.java:211)

at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:142)

at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1360)

at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1414)

at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:602)

at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:876)

at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:872)

at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:97)

at com.jfinal.plugin.activerecord.TableBuilder.build(TableBuilder.java:38)

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

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

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

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.JettyServer.doStart(JettyServer.java:131)

at com.jfinal.server.JettyServer.start(JettyServer.java:70)

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

at com.hm.astock.manage.config.ManageConfig.main(ManageConfig.java:124)

Caused by: java.lang.IllegalAccessError: class sun.reflect.GeneratedConstructorAccessor2 cannot access its superclass sun.reflect.ConstructorAccessorImpl

at sun.misc.Unsafe.defineClass(Native Method)

at sun.reflect.ClassDefiner.defineClass(ClassDefiner.java:63)

at sun.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:399)

at sun.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:394)

at java.security.AccessController.doPrivileged(Native Method)

at sun.reflect.MethodAccessorGenerator.generate(MethodAccessorGenerator.java:393)

at sun.reflect.MethodAccessorGenerator.generateConstructor(MethodAccessorGenerator.java:92)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:55)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.lang.reflect.Constructor.newInstance(Constructor.java:422)

at com.mysql.jdbc.Util.handleNewInstance(Util.java:400)

at com.mysql.jdbc.ResultSetImpl.getInstance(ResultSetImpl.java:339)

at com.mysql.jdbc.MysqlIO.buildResultSetWithRows(MysqlIO.java:3026)

at com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:469)

at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:3009)

at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:2257)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2650)

at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2541)

at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2499)

at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1432)

at com.mysql.jdbc.ConnectionImpl.loadServerVariables(ConnectionImpl.java:3870)

at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3284)

at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2122)

at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2084)

at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:794)

at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.lang.reflect.Constructor.newInstance(Constructor.java:422)

at com.mysql.jdbc.Util.handleNewInstance(Util.java:400)

... 34 more

Can not create Table object, maybe the table account_bank is not exists.

2017-03-04 16:34:48[ERROR]-[Thread: main]-[com.jfinal.core.Config.startPlugins()]: Plugin start error: com.jfinal.plugin.activerecord.ActiveRecordPlugin. 

java.sql.SQLException: Error

com.jfinal.plugin.activerecord.ActiveRecordException: java.sql.SQLException: Error

at com.jfinal.plugin.activerecord.TableBuilder.build(TableBuilder.java:50)

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

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

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

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.JettyServer.doStart(JettyServer.java:131)

at com.jfinal.server.JettyServer.start(JettyServer.java:70)

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

at com.hm.astock.manage.config.ManageConfig.main(ManageConfig.java:124)

Caused by: java.sql.SQLException: Error

at com.alibaba.druid.pool.DruidDataSource.handleConnectionException(DruidDataSource.java:1116)

at com.alibaba.druid.pool.DruidPooledConnection.handleException(DruidPooledConnection.java:127)

at com.alibaba.druid.pool.DruidPooledStatement.checkException(DruidPooledStatement.java:68)

at com.alibaba.druid.pool.DruidPooledStatement.executeQuery(DruidPooledStatement.java:154)

at com.jfinal.plugin.activerecord.TableBuilder.doBuild(TableBuilder.java:66)

at com.jfinal.plugin.activerecord.TableBuilder.build(TableBuilder.java:42)

... 20 more

Caused by: java.lang.ExceptionInInitializerError

at com.alibaba.druid.wall.spi.MySqlWallVisitor.preVisit(MySqlWallVisitor.java:394)

at com.alibaba.druid.sql.ast.SQLObjectImpl.accept(SQLObjectImpl.java:38)

at com.alibaba.druid.wall.WallProvider.checkInternal(WallProvider.java:656)

at com.alibaba.druid.wall.WallProvider.check(WallProvider.java:586)

at com.alibaba.druid.wall.WallFilter.check(WallFilter.java:694)

at com.alibaba.druid.wall.WallFilter.statement_executeQuery(WallFilter.java:491)

at com.alibaba.druid.filter.FilterChainImpl.statement_executeQuery(FilterChainImpl.java:2360)

at com.alibaba.druid.filter.FilterAdapter.statement_executeQuery(FilterAdapter.java:2482)

at com.alibaba.druid.filter.FilterEventAdapter.statement_executeQuery(FilterEventAdapter.java:302)

at com.alibaba.druid.filter.FilterChainImpl.statement_executeQuery(FilterChainImpl.java:2360)

at com.alibaba.druid.proxy.jdbc.StatementProxyImpl.executeQuery(StatementProxyImpl.java:211)

at com.alibaba.druid.pool.DruidPooledStatement.executeQuery(DruidPooledStatement.java:143)

... 22 more

 1.使用的Druid版本是1.0.5.

 2.debug后发现是在启动plugin时报错。

3.错误信息中提到 Can not create Table object, maybe the table account_bank is not exists. 我可以确定数据库中是有这个表的。

实在找不到原因,来求助了 @JFINAL

评论区

JFinal

2017-03-04 16:48

如果是用的 IDEA,并且是用的 jfinal 集成的 jetty 启动项目,使用如下代码:
JFinal.start("WebRoot", 80, "/");

而不要使用如下代码:
JFinal.start("WebRoot", 80, "/", 5);

也就是说,IDEA 下的启动少了最后一个 int 型参数,这是由于 IDEA 启动时无法切换成 jfinal 自定义的 classloader 引发的,下载首页的 jfinal demo,看一下 DemoConfig.main() 方法中的说明文字

记得搞定后再回复一下该贴

fengting

2017-03-04 16:50

好吧,升级之后确定没注意这个。谢谢啊!!!

JFinal

2017-03-04 16:59

@fengting jfinal 手册第一章介绍了如何升级,其中谈到了这点,搞定了没?

fengting

2017-03-07 15:24

@JFinal 嗯嗯,搞定了。没看文档,文档开头提到的一些注意事项都踩了一遍。

JFinal

2017-03-07 15:29

@fengting jfinal 手册中,只要是红色字体部分,就非常重要,否则容易出问题,一旦知道了,后面就没阻力了,都是些简单规则

fengting

2017-03-07 15:34

@JFinal 嗯嗯,是的。3.0升级的文档哪里有啊,我想看看,刚才找了半天没找到。

JFinal

2017-03-07 15:36

@fengting jfinal 3.0 手册第一章啊,首页右侧有下载的啊

fengting

2017-03-07 16:25

@JFinal 说错了,我想看看升级的日志文档,就是3.0升级的功能,不是3.0的手册

JFinal

2017-03-07 16:27

@fengting jfinal.com 首页右侧就有 changelog.txt 下载啊

老贲

2017-07-30 10:15

JFinal.start("WebRoot", 80, "/"); 为什么我直接写会报错

fengting

2017-07-31 21:31

@老贲 这是我项目中的写法 确保你的jfinal版本是3.0及以上 public static void main(String args[]) {
String webPath = System.getProperty("user.dir") + "\\xxx\\src\\main\\webapp";
JFinal.start(webPath, 9999, "/");
}

梦下花开

2017-10-17 14:20

我用的eclipse版本是Oxygen.1a Release (4.7.1a),也是这个错误,去掉最后一个参数就好!!!已经被气哭n次了!至今旧一点的版本是要加原来的参数的。

henterchow

2017-10-17 15:04

@JFinal 这个问题不能从框架层面兼容吗?

JFinal

2017-10-17 15:27

@梦下花开 @henterchow 这个问题还不知道原因,我自己用的是 eclipse mars 这个版本

梦下花开

2017-10-17 16:56

@JFinal 波总,最新版的eclipse好像不能热加载了,害的我每次都要手动重启项目...

JFinal

2017-10-17 16:58

@梦下花开 不是不支持,而是你把 JFinal.start(....) 的最后一个 int 型参数去掉了,去掉这个参数本身就是不支持的,必须要添加上那个参数

梦下花开

2017-10-17 17:20

@JFinal 这就尴尬了,加上运行不起来,不加又得手动重启

JFinal

2017-10-17 17:26

@梦下花开 其实还是要先搞懂为啥启动不起来,我没有用这个 eclipse 版本,也就不知道是啥问题,如果你找到原因,别忘了回来分享一下 ^_^

梦下花开

2017-10-18 09:49

迷糊的猴子

2017-11-01 16:13

@JFinal eclispe Oxygen 版本不能用热加载

JFinal

2017-11-01 17:23

@迷糊的猴子 使用eclipse 4.6 就好了。4.7 也是ok的,4.7.1a不行。

迷糊的猴子

2017-11-01 18:09

@JFinal 我还是老老实实用回eclipse mars

flyamber

2017-11-17 17:04

eclipse4.7.1导入3.2 Demo项目直接运行会报错,但是改用IDEA的参数(即把最后一个参数去掉)就可以正常运行

sokoo

2017-12-07 16:03

@JFinal Jfinal3.3在Eclipse Oxygen.1a Release (4.7.1a)版本中也不能加最后的int参数,否则报同样的错误!

JFinal

2017-12-07 17:46

@flyamber @sokoo 参考这个回贴解决:http://www.jfinal.com/feedback/2429

热门反馈

扫码入社