拒绝对尚未发布的文件的发布文件请求。尝试了所有选项但没有用

Rejecting published file request for file that has not been published. Tried all the options but didn't work

我正在尝试实现一个示例应用程序,其中所有 javascript (JS) 和 CSS 文件都使用许多 png 文件。

我参考了很多文章,但它们对我没有帮助。

对于所有 png 文件,我收到以下错误,

示例错误部分,

Jan 29, 2019 3:25:22 PM com.vaadin.server.communication.PublishedFileHandler handleRequest
WARNING: Rejecting published file request for file that has not been published: css/images/chartIcon.png
Jan 29, 2019 3:25:22 PM com.vaadin.server.communication.PublishedFileHandler handleRequest
WARNING: Rejecting published file request for file that has not been published: css/images/sunburst.png
Jan 29, 2019 3:25:22 PM com.vaadin.server.communication.PublishedFileHandler handleRequest
WARNING: Rejecting published file request for file that has not been published: css/images/treemap.png
Jan 29, 2019 3:25:40 PM com.vaadin.server.communication.PublishedFileHandler handleRequest
WARNING: Rejecting published file request for file that has not been published: css/images/sprite.png

以下是我的文件夹结构,

de.qsoft.manatee.web.vaadin.myapp

de.qsoft.manatee.web.vaadin.myapp.css  --> Contains all CSS files
de.qsoft.manatee.web.vaadin.myapp.fileMenu --> Contains all CSS files
de.qsoft.manatee.web.vaadin.myapp.widgets --> Contains all CSS files

de.qsoft.manatee.web.vaadin.myapp.scripts  --> contains all js files
de.qsoft.manatee.web.vaadin.myapp.widgets  --> contains all js files
de.qsoft.manatee.web.vaadin.myapp.colorpicker  --> contains all js files

SpreadJSWidget.Java

@JavaScript({
   "scripts/jquery-1.11.1.min.js",
   "scripts/jquery-ui-1.10.3.custom.min.js",
   "spreadjs_connector.js",
   "colorpicker/colorPicker.js",
   "fileMenu/fileMenu.js",
   "scripts/actionmanager.js",
   "scripts/app.js",
   "scripts/bootstrap.min.js",
   "scripts/FileSaver.min.js",
   "scripts/gc.spread.excelio.12.0.5.min.js",
   "scripts/gc.spread.sheets.all.12.0.5.min.js",
   "scripts/gc.spread.sheets.barcode.12.0.5.min.js",
   "scripts/gc.spread.sheets.charts.12.0.5.min.js",
   "scripts/gc.spread.sheets.pdf.12.0.5.min.js",
   "scripts/gc.spread.sheets.print.12.0.5.min.js",
   "scripts/gc.spread.sheets.shapes.12.0.5.min.js",
   "scripts/license.js",
   "scripts/resources.js",
   "scripts/ribbon-data.js",
   "scripts/ribbon.js",
   "scripts/sample.js",
   "scripts/spreadActions.js",
   "scripts/util.js",
   "widgets/addChartElement/chartAddChartElement.js",
   "widgets/chartColorPicker/chart-colorPicker.js",
   "widgets/chartLayoutPicker/chartLayoutPicker.js",
   "widgets/richText/richTextEditor.js"
   })


@StyleSheet({
   "colorpicker/colorPicker.css",
   "css/font-awesome/css/font-awesome.min.css",
   "css/bootstrap-theme.min.css",
   "css/bootstrap.min.css",
   "css/borderpicker.css",
   "css/colorpicker.css",
   "css/excel2013.css",
   "css/gc.spread.sheets.12.0.5.css",
   "css/gc.spread.sheets.excel2013white.12.0.5.css",
   "css/insp-slicer-format.css",
   "css/insp-table-format.css",
   "css/inspector.css",
   "css/sample.css",
   "css/shapes.css",
   "fileMenu/fileMenu.css",
   "widgets/addChartElement/chartAddChartElement.css",
   "widgets/chartColorPicker/chart-colorPicker.css",
   "widgets/chartLayoutPicker/chartLayoutPicker.css",
   "widgets/richText/richTextWithRichEditor.css",
   })



public class SpreadJSWidget extends AbstractJavaScriptExtension
{
   /**
    * 
    */
   private static final long serialVersionUID = -804316208810859887L;

   public interface ValueChangeListener extends Serializable {
      void valueChange();
   }

   ArrayList<ValueChangeListener> listeners = new ArrayList<ValueChangeListener>();

   public void addValueChangeListener(ValueChangeListener listener) {
      listeners.add(listener);
   }



   /**
    * 
    */
   public SpreadJSWidget() {
      // TODO hari: Auto-generated constructor stub
   }
   /*'***************************************************************************************
   *   Static/Inner class members                                         
   ******************************************************************************************/

   /*'***************************************************************************************
   *   Class members                                         
   ******************************************************************************************/

   public void setValue(String value) {
      getState().value = value;
   }


   @Override 
   protected void extend(AbstractClientConnector target) {
      // TODO hari: Not Yet Implemented
      super.extend(target);
   }


   public String getValue() {
      return getState().value;
   }

   @Override protected SpreadJSWidgetState getState() {
      return (SpreadJSWidgetState) super.getState();
   }

}

我逐步尝试了以下步骤,但无法获得预期的结果,

  1. 我把所有的png文件都保存在目录"de.qsoft.manatee.web.vaadin.myapp.css"下,如"de.qsoft.manatee.web.vaadin.myapp.css.images"

  2. 在 VAADIN 文件夹下,我将所有 png 文件复制为 "VAADIN/css/images/"

  3. 在 VAADIN 文件夹下 "VAADIN/themes/mytheme/img/css/images"

  4. 在 VAADIN 文件夹下 "VAADIN/themes/mytheme/layouts/css/images"

    @主题("mytheme") public class 我的UI 扩展 UI {

    @Override
    protected void init(VaadinRequest vaadinRequest) {
    
    SpreadWidget widget = new SpreadWidget();
    setContent(widget);
    
    
    }
    
    @WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
    @VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
    public static class MyUIServlet extends VaadinServlet {
    }
    

    }

请让我知道我应该把所有 png 文件放在哪里。每个 css 都将图像文件引用为

http://localhost:8080/spreadjs/APP/PUBLISHED/css/images/AllShapes.png

这里发生的事情是由安全功能引起的。由于在这种情况下文件是直接从类路径提供的,Vaadin 采取了一些预防措施来防止意外地从类路径发布其他内容,例如类似 DatabaseConnection.java 的内容可能包含敏感密码。

因此,只有使用 @StyleSheet@JavaScript@HtmlImport 注释明确发布的文件才可用。由于没有相应的注释,例如css/images/AllShapes.png,服务器忽略这些请求。

我知道在这种情况下有几个潜在的解决方法,但都不是很优雅:

  1. 将图像放入例如VAADIN/css/images 并更新 CSS 以使用适当数量的 ../ 段来抵消 URL 的 /APP/PUBLISHED/ 部分。 CSS 中的 URL 因此类似于 ../../VAADIN/css/images.AllShapes.png.
  2. 将 CSS 与图像放在 VAADIN/ 中。这样,您不需要更改引用图像的 URL,而是需要手动加载 CSS 而不是依赖方便的 @StyleSheet 注释。在那种情况下,我建议使用 ui.getPage().getStyles().add(new ThemeResource("../../css/name.css")); 之类的东西。 ../../ 部分是为了取消 themes/mytheme/ 将自动用于主题资源。你可以这样做attach() 方法(记住还要调用 super.attach())。您最好还添加一些逻辑,如果之前还没有为相同的 UI 实例添加依赖项,则只添加依赖项。
  3. 使用内部 LegacyCommunicationManager.registerDependency 方法也可以注册您的图像,以便直接从类路径中使用。您可以使用 vaadinSession.getCommunicationManager().
  4. 找到 LegacyCommunicationManager 的实例

作为一个不相关的说明,我建议将不同的脚本和 CSS 文件合并到每种类型的单个文件中。这样做的原因是通过 HTTP 加载大量小文件会导致一些性能开销,可以通过将文件捆绑在一起来避免。