java - 带 Spring Boot 的 ZK CKEditor 自定义插件

标签 java spring-boot ckeditor zk ajp

我正在将 ZK 标准 Spring 应用程序迁移到 Spring Boot

我的 CKEditor 配置有问题。我正在使用外部插件,以下是配置:

CKEDITOR.plugins.addExternal('wordcount', 'plugins/wordcount/', 'plugin.js');
CKEDITOR.plugins.addExternal('notification', 'plugins/notification/', 'plugin.js');

CKEDITOR.editorConfig = function (config) {
    config.extraPlugins = 'wordcount,notification';
    config.mytoolbar = [ ... ]
    config.wordcount = { ... };
};
<小时/>

对于旧的标准 Spring 应用程序,我以这种方式配置它:

1 - 插件(字数通知文件夹)放入src/webapp/zkpatch/js/ckez/ext/CKeditor/插件

2 - ckeditor 配置文件 (config.js) 放入 src/webapp/js

3 - 在 zk.xml 中:

<library-property>
    <name>org.zkoss.web.util.resource.dir</name>
    <value>/zkpatch</value>
</library-property>

4 - 在 ZUL 文件中:

<ckeditor customConfigurationsPath="/js/config-ckeditor.js" value="@load(vm.myvalue)"/>

这非常有效。

<小时/>

使用Spring Boot,资源位置已更改,因此我使用以下内容:

1 - 插件(字数通知文件夹)放入src/resources/web/zul/js/ckez/ext/CKeditor/插件

2 - ckeditor 配置文件 (config.js) 放入 src/resources/static/js

3 - 在 ZUL 文件中:

<ckeditor customConfigurationsPath="/js/config-ckeditor.js" value="@load(vm.myvalue)"/>

但是到达该页面时出现以下错误(ZK 弹出窗口):

/js/ckez/ext/CKeditor/plugins/wordcount/plugin.js not found

从页面源码中可以看到插件JavaScript文件已正确加载,浏览器控制台中也出现TypeError: k is null错误。

我需要将自定义插件文件夹移动到哪里以便 Spring Boot 可以找到它们?

<小时/>

编辑 1

我错过了上面的一些路径,我当然使用src/main/resources而不是src/resources,并且CKEditor插件文件夹已放入 >src/resources/web/js/ckez/ext/CKeditor/plugins(不在 zul 文件夹中)。

我忘了提及,我们正在使用自定义应用程序初始值设定项来支持自定义范围(我的一位同事在此处提出了一个问题 https://github.com/zkoss/zkspringboot/issues/7 )。

我们使用 Java 11ZK 8.6.0zkspringboot 1.0.3 starter 以及 Spring boot 2.0 .5.RELEASE (我上次尝试了 2.1.0,但似乎它与您的启动器还不兼容,顺便说一句,如果能够使用 2.1.0 版本 进行生产,那就太好了因为它正式支持 java 11)。

<小时/>

编辑2

Undertow 配置了 HTTPSHTTP/2

当直接访问应用程序( https://locahost:8443/myapp )时,我确实没有遇到任何问题,CKEditor 加载正常。

我刚刚注意到,当我使用带有 AJP ( https://locahost/myapp ) 的前端 Apache 服务器时,会出现问题,然后 CKEditor 无法加载并显示上述错误消息。我可以从浏览器网络选项卡中看到,我还获得了一些静态资源(自定义 js/css)的代码 403。

Apache 配置非常基本:

ProxyPass "/myapp" "ajp://localhost:8009/myapp"
ProxyPassReverse "/myapp" "ajp://localhost:8009/myapp"

Undertow 配置也:

@Configuration
public class UndertowEmbeddedAjpConfiguration {

    public UndertowEmbeddedAjpConfiguration() { }

    @Bean
    public UndertowServletWebServerFactory undertowServletWebServerFactory() {
        final UndertowServletWebServerFactory undertow = new UndertowServletWebServerFactory();
        undertow.addBuilderCustomizers((UndertowBuilderCustomizer) builder -> {
            builder.addAjpListener(8009, "localhost");
        });
        return undertow;
    }
}

我知道 AJP 已经过时了,不幸的是,这是我们的要求,因为我们被迫为所有应用程序使用 Shibboleth SSO,这需要 AJP...

如果需要,我可以提供一个随时可用的 Docker 版本。

编辑3

在我升级了一些依赖项后,问题终于消失了。不幸的是,我没有注意到哪些,因为我在多次部署后几周后才意识到......

最佳答案

这很难解决,但我会尝试。

“org.zkoss.web.util.resource.dir”配置的额外文件夹从来都不是必需的。并且实际上只对补丁有用,因为您只能配置其中之一。

放置资源的旧/原始位置位于包文件夹 src/main/resources/web 中(或者您可能使用非默认的 src/resources/web >) - 这就是您在查看任何 ZK jar 时会看到的内容......这种机制一直可供任何人使用。

因此,Spring Boot 应用程序中没有什么新内容,区别在于将 Spring Boot 应用程序构建为 jar 文件时,WEB-INF 文件夹不可用。

我认为这只是您的配置中的拼写错误:

1 - plugins (wordcount and notification folders) put in src/resources/web/zul/js/ckez/ext/CKeditor/plugins

ckeditor将在类路径文件夹web/js/ckez/ext/CKeditor/plugins中搜索插件,中间没有zul,只需遵循与ckez.jar

这应该可以修复错误/js/ckez/ext/CKeditor/plugins/wordcount/plugin.js not found

也许这已经是您所需要的了。

为了解决其他问题,我建议查看浏览器开发人员工具 - 网络选项卡。这将为您提供有关使用哪个路径加载文件以及服务器如何响应的更好(不仅仅是页面源)信息。

关于java - 带 Spring Boot 的 ZK CKEditor 自定义插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53544728/

相关文章:

java - Magento Rest Oauth API(签名无效)401

java - 当文本字段聚焦时,Windows 平板电脑触摸键盘不会弹出

java - 得到 "undefined method ` [ ]' for nil:NilClass"安装 java Cookbook

java - 当运行 spring Boot 应用程序时,需要一个无法找到的类型的 bean

javascript - setData 命令不是每次都将我的数据设置为 CKEDITOR

javascript - 使用 Promise 进行 CKEditor 5 模型转换

java - 当您释放移动矩形的键时,如何让矩形停止?

java - 如何从 thymeleaf 的 URL 中隐藏模型数据?

java - 配置属性注释问题

jquery - 如何禁用所有用作ckeditor的文本区域