| 类 | 说明 |
|---|---|
| CompositeResourceManager |
CompositeResourceManager
|
| PathKitExt |
PathKitExt 用于扩展 com.jfinal.kit.PathKit,同时支持开发环境与部署环境
解决 PathKit.getWebRootPath()/getRootClassPath() 在部署环境下无法正常
工作的问题
一、问题描述
1:jfinal-undertow 打包部署启动时在 com.jfinal.core.Config.initEngine() 中
调用 PathKit.getWebRootPath()/detectWebRootPath() 会抛出 NPE
引起异常的原因应该是 JFinal.initPathKit() 中的 servletContext.getRealPath("/")
得到的是一个 null 值,造成 PathKit.setWebRootPath(null) 注入的是 null 值,从而后续
Config.initEngine() 间接调用 PathKit.detectWebRootPath() 引发 NPE
在部署环境之下,由于 servletContext.getRealPath("/") 返回 null,而且 PathKit 中的
ClassLoader.getResource("")、PathKit.class.getResource("/") 也不能正常工作
合力引发 NPE
2:jfinal-undertow 部署方式之下 PathKit.getWebRootPath()、getRootClassPath()
都会报出异常,为 PathKit 的 rootClassPath、webRootPath 事先注入值,避免抛出异常
3:由于 com.jfinal.kit.PathKit 历史久远,为兼容性起见不便进行改造
二、解决方案
1:一种手动处理的办法是用户在 JFinalConfig 继承类中的 configConstant(Constants me)
中调用 PathKit.setWebRootPath()、PathKit.setRootClassPath() 注入值
在该处手动注入的时机处于 JFinal.initPathKit() 之后与 Config.initEngine() 之前
这两个值可以配置在外部配置文件中便于修改,但此法增加了配置工作量
2:通过 PathKitExt 生成合理的 rootClassPath、webRootPath 并通过反射的方式
注入到 com.jfinal.kit.PathKit 之中两个对应的变量之中
关键在于生成的 rootClassPath、webRootPath 值需要同时满足开发环境与打包部署环境
具体的生成逻辑放在 buildRootClassPath()、buildWebRootPath() 的注释中
3:要兼顾三种情况:开发环境、fatjar 部署、"非fatjar" 部署
|
| PropExt |
PropExt
支持 undertow 从 config 目录以及 jar 包中读取配置文件
|
| ResourceManagerBuilder |
1:FileResourceManager 支持在普通目录下去加载 css、js 等 web 静态资源
2:ClassPathResourceManager 支持在 classpath 下与 jar 包内加载 css、js
等 web 静态资源
3:ClassPathResourceManager 第二个参数不能省略,也不能为 "",否则可以在浏览器地址栏直接访问
class path、jar 中的所有资源,包括配置文件,下面的用法极其危险:
new ClassPathResourceManager(getClassLoader()));
4:在需要用到 ClassPathResourceManager 时为其给定一个参数,例如:
new ClassPathResourceManager(getClassLoader(), "webapp"));
上例给定 webapp 参数,undertow 可以从 classpath、jar 包内的
webapp 之下去加载 web 静态资源
|
| UndertowConfig |
UndertowConfig
|
| UndertowKit | |
| UndertowServer |
UndertowServer
官方示例:https://github.com/undertow-io/undertow/tree/master/examples/src/main/java/io/undertow/examples
注意:关闭服务时使用:kill pid,不要使用:kill -9 pid,
否则 JFinalConfig.beforeJFinalStop() 不会被回调
文档:
http://undertow.io/undertow-docs/undertow-docs-2.0.0/index.html
https://blog.csdn.net/zhaowen25/article/details/45324805
|
| WebBuilder |
WebBuilder 用于构建 WebSocket、Filter、Servlet、Listener
缩减 UndertowServer、UndertowConfig 代码,简化配置
|
| WebSocketConfig |
WebSocketConfig 将 WebSocket 功能所依赖的 jar 包从 UndertowServer
中隔离出来,从而 "非 WebSocket" 项目不必引入 WebSocket 相关 jar 包
而不会报出 ClassNotFound 异常
undertow websocket 官方示例:
https://github.com/undertow-io/undertow/tree/master/examples/src/main/java/io/undertow/examples/jsrwebsockets
|
| 异常错误 | 说明 |
|---|---|
| PropExt.FileNotFoundException |
Copyright © 2019. All rights reserved.