JFinal开发web项目出现故障小记

JFinal开发web项目出现故障小记

大家好,又见面了,我是全栈君。

导读

作为中国优秀的开源项目之中的一个JFinal有着极速开发的优点,是中小型应用开发的首选。在导师的建议下。我使用了JFinal来开发一个Java服务端应用,官方教程非常easy。就几十页(当然是中文的),学起来非常快。

然而在开发过程中肯定会遇到这样那样“无厘头”的问题,怎样使用JFinal开发參考官方文档或网上某些人的教程就可以,我再重写一遍也无多大意义。我这篇文章仅记录自己在使用JFinal开发过程中遇到的问题及注意事项,这样更有參考价值,也希望大家在遇到相似的问题后能及时找到解决方式,提高开发效率。

JFinal开发问题集锦

1. 中文乱码问题

这是差点儿每一个进行Java web开发的程序猿都遇到过的问题。不同技术或框架处理的方式可能不太一样。对JFinal来说。有以下几个配置字符集的地方:

(1)Config配置:

YourJFinalConfig.configConstant(Constants me) {me.setEncoding("utf-8")};

(2)数据库连接配置:

jdbcUrl = jdbc:mysql://127.0.0.1/jfinal?characterEncoding=utf8

(3)假设是页面发送 GET 请求,中文字符须要 encoding,除非在 tomcat 的 server.xml 中的 Connector 标记中加入了 URIEncoding=”UTF-8″ 属性

(4)假设是 jsp 页面:

<%@ page language="java" contentType="text/html; charset=UTF-8" 
pageEncoding="UTF-8"%>

(5)假设是其他 html 页面:

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

(6)另外 eclipse workspace 的字符编码最好也配置成 utf-8

2. “Illegal access”问题

出现这样的问题的解决办法非常多,比方我遇到的有以下3种:

情况1INFO: Illegal access: this web application instance has been stopped already. Could not load com.mysql.jdbc.authentication.MysqlOldPasswordPlugin. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact. 情况2INFO: Illegal access: this web application instance has been stopped already. Could not load com.mchange.v2.c3p0.ConnectionCustomizer. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact. 情况3INFO: Illegal access: this web application instance has been stopped already. Could not load com.mchange.v2.resourcepool.BasicResourcePool$1. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact. 

解决方法: 查看上述日志,可能会非常明显的看到以下非常多的exception。都是this web application instance has been stopped already以及Could not load XX Class。

可是不要被这些异常迷惑,他们仅仅是结果而不是原因。那么假设查找原因,能够通过查找error-debug日志文件来解决。

error-debug日志文件日志文件默认是不生成的,我们须要通过log配置文件来设置让其生成,详细方法例如以下:
(1)在WEB-INF/classes文件夹下新建logging.properties,内容例如以下:

handlers = org.apache.juli.FileHandler, java.util.logging.ConsoleHandler ############################################################ # Handler specific properties. # Describes specific configuration info for Handlers. ############################################################ org.apache.juli.FileHandler.level = FINE org.apache.juli.FileHandler.directory = ${应用文件夹}/logs org.apache.juli.FileHandler.prefix = error-debug. java.util.logging.ConsoleHandler.level = FINE java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter 

(2)又一次启动应用。指定文件夹下会有一个error-debug.yyyy-mm-ss.log的错误日志。通过分析上述日志能够找到问题发生的真正原因。然后进行解决。

3. “Plugin start error”问题

java.lang.RuntimeException: Plugin start error: com.jfinal.plugin.activerecord.ActiveRecordPlugin. java.sql.SQLException: Connections could not be acquired from the underlying database! at com.jfinal.core.Config.startPlugins(Config.java:95) at com.jfinal.core.Config.configJFinal(Config.java:48) at com.jfinal.core.JFinal.init(JFinal.java:67) at com.jfinal.core.JFinalFilter.init(JFinalFilter.java:49) at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:277) at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:258) at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:382) at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:103) at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4649) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5305) 

解决方法: 删除跟jetty相关的jar包,由于我是在Tomcat下部署的。而JFinal自带的是jetty服务器。

4. 启动时老是出现“jfinal config it in web.xml”错误

解决方法: 删除web.xml中默认生成的以下这段:

 <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> 

5. 缺少c3p0的jar包会出现以下错误:

java.lang.NoClassDefFoundError: com/mchange/v2/c3p0/ComboPooledDataSource at com.jfinal.plugin.c3p0.C3p0Plugin.start(C3p0Plugin.java:145) at com.jfinal.core.Config.startPlugins(Config.java:85) at com.jfinal.core.Config.configJFinal(Config.java:48) at com.jfinal.core.JFinal.init(JFinal.java:67) at com.jfinal.core.JFinalFilter.init(JFinalFilter.java:49) at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279) at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260) at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105) at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4809) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5485) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) Caused by: java.lang.ClassNotFoundException: com.mchange.v2.c3p0.ComboPooledDataSource at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571) ... 18 more 

而缺少与c3p0一起的mchange-commons-java-0.2.7.jar包。会出现以下错误:

java.lang.NoClassDefFoundError: com/mchange/v2/ser/Indirector at com.jfinal.plugin.c3p0.C3p0Plugin.start(C3p0Plugin.java:145) at com.jfinal.core.Config.startPlugins(Config.java:85) at com.jfinal.core.Config.configJFinal(Config.java:48) at com.jfinal.core.JFinal.init(JFinal.java:67) at com.jfinal.core.JFinalFilter.init(JFinalFilter.java:49) at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279) at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260) at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105) at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4809) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5485) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) Caused by: java.lang.ClassNotFoundException: com.mchange.v2.ser.Indirector at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571) ... 18 more 

6. freemarker相关的jar包缺乏问题:

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at com.jfinal.core.ActionInvocation.invoke(ActionInvocation.java:61) at com.jfinal.core.ActionHandler.handle(ActionHandler.java:77) at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:72) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:662) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.jfinal.core.ActionInvocation.invoke(ActionInvocation.java:55) ... 19 more Caused by: java.lang.NoClassDefFoundError: freemarker/template/TemplateException at com.jfinal.render.RenderFactory$FreeMarkerRenderFactory.getRender(RenderFactory.java:233) at com.jfinal.render.RenderFactory.getRender(RenderFactory.java:127) at com.jfinal.core.Controller.render(Controller.java:892) at com.demo.controller.StudentController.index(StudentController.java:16) ... 24 more Caused by: java.lang.ClassNotFoundException: freemarker.template.TemplateException at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571) ... 28 more 

解决方法: JFinal 默认使用 FreeMarker作为 View,故需freemarker的jar包

參考资料

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/115922.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • 强大的自适应jQuery焦点图特效

    jQuery焦点图切换自适应效果自适应jQuery焦点图特效是一款支持移动端的响应式jQuery焦点图插件,支持flexible布局,支持移动触摸事件等。今天我们要来分享一款很灵活的jQuery焦点图

    2021年12月21日
  • visual studio2015下载_使用visual studio

    visual studio2015下载_使用visual studiovs2013下地址:ed2k://|file|cn_visual_studio_professional_2013_x86_dvd_3009203.iso|3020535808|133B4703B20B4E78C1742E3AC8665CBC|/大小:2.81GBvs2013旗舰版下地址:ed2k://|file|cn_visual_

  • Java面试题大全(2020版)[通俗易懂]

    发现网上很多Java面试题都没有答案,所以花了很长时间搜集整理出来了这套Java面试题大全,希望对大家有帮助哈~本套Java面试题大全,全的不能再全,哈哈~一、Java基础1.JDK和JRE有什么区别?JDK:JavaDevelopmentKit的简称,java开发工具包,提供了java的开发环境和运行环境。 JRE:JavaRuntimeEnviron…

  • 一个wml的实例(原创)

    一个wml的实例(原创)

  • 10个的常用PyCharm插件

    10个的常用PyCharm插件安装方法先来说说插件的安装方法,一点都不难。选择顶部菜单栏的PyCharm选项,打开Preferences,点击plugins,在右侧的文本框中输入想要查看的插件名称,在下方就会罗列出已经安装的相关的插件。找到我们所需要的对应插件之后,点击install即可完成下载,然后重启一下Pycharm即可插件介绍1、MaterialThemeUILite该插件的作用在于能够为Pycharm提供多种不同的页面风格。设置:选择顶部菜单栏的PyCharm选项,打开Pref

  • php vld_phpenv使用教程

    php vld_phpenv使用教程1、查看本地是否已经安装了vld扩展,如果没有任何输出,那就准备安装吧![root@taiwu~]#/home/work/lib/php5.6.7/bin/php-m|grepvld2、去官方网站下载vld(http://pecl.php.net/package/vld),找到最新版本,右键复制地址链接就能得到下载地址,通过浏览器直接下载也行。我是通过wget命令在centos的命…

    2022年10月30日

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号