JFinal快速啟動異常
阿新 • • 發佈:2018-11-02
1.使用eclipse
啟動jfinal_demo
先要在res/a_little_config.txt
中配置正確的資料庫連線使用者名稱和密碼;
2.使用J2EE的方式嘗試啟動DemoConfig
遇到以下錯誤:
[ERROR]-[Thread: main]-[com.alibaba.druid.pool.DruidDataSource.init()]: init datasource error, url: jdbc:mysql://127.0.0.1:3306/jfinal_demo?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull& useSSL=false
java.sql.SQLException: java.lang.IllegalAccessError: class sun.reflect.GeneratedConstructorAccessor1 cannot access its superclass sun.reflect.ConstructorAccessorImpl
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964)
at com.mysql.jdbc.SQLError.createSQLException(SQLError. java:897)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:877)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:873)
at com.mysql.jdbc.Util.handleNewInstance (Util.java:443)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:389)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1461)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1525)
at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:734)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1060)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1056)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:104)
at com.jfinal.plugin.activerecord.TableBuilder.build(TableBuilder.java:43)
at com.jfinal.plugin.activerecord.ActiveRecordPlugin.start(ActiveRecordPlugin.java:226)
at com.jfinal.core.Config.startPlugins(Config.java:128)
at com.jfinal.core.Config.configPluginWithOrder(Config.java:71)
at com.jfinal.core.Config.configJFinal(Config.java:56)
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:133)
at com.jfinal.server.JettyServer.start(JettyServer.java:70)
at com.jfinal.core.JFinal.start(JFinal.java:162)
at com.demo.common.DemoConfig.main(DemoConfig.java:37)
Caused by: java.lang.IllegalAccessError: class sun.reflect.GeneratedConstructorAccessor1 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:425)
at com.mysql.jdbc.ResultSetImpl.getInstance(ResultSetImpl.java:342)
at com.mysql.jdbc.MysqlIO.buildResultSetWithRows(MysqlIO.java:3129)
at com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:476)
at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:3112)
at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:2341)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2736)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2483)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2441)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1381)
at com.mysql.jdbc.ConnectionImpl.loadServerVariables(ConnectionImpl.java:3790)
at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3227)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2235)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2017)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:779)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
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:425)
... 30 more
3.原因分析:這可能是資料庫資料來源配置與Jetty容器熱啟動有衝突。
JFinal.start("WebRoot", 80, "/", 5);
這個地方,跟使用IDEA
一樣,需要去掉最後一個引數,即:
JFinal.start("WebRoot", 80, "/");
服務啟動正常。
最後一個引數“5”,是配置Jetty容器<scanIntervalSeconds>
,是一個可選引數,用於配置Web應用掃描的間隔時間,Web應用掃描如果發現修改了程式,會自動重新部署。該引數預設值為0,即不啟動熱部署。
PS:筆者從GitHub下載的其他JFinal專案啟動時,JFinal.start(“WebRoot”, 80, “/”, 5)並沒有異常。