maven - 使用 Maven 和 Spring Boot 的 Vaadin 自定义组件/小部件

标签 maven gwt spring-boot vaadin7

我对 vaadin 比较陌生,从 Spring Boot 应用程序和 vaadin Spring Boot 插件开始。一切都工作正常,直到我尝试创建自己的组件/小部件。

不幸的是,我没有找到任何“官方”示例/文档,说明如何在 Spring Boot 应用程序中设置自定义组件,因此我不得不搜索网络以了解如何在 Maven 中设置其他插件进行编译客户端小部件的代码。据我从日志输出中可以看出,这些组件的编译工作正常,但是当我尝试在网页上访问这些组件时,出现错误:

Widgetset 'com.vaadin.DefaultWidgetSet' does not contain implementation for net.gtidev.test.components.MyComponent. Check its component connector's @Connect mapping, widgetsets GWT module description file and re-compile your widgetset. [...]

这是小部件编译器日志:

[INFO] Using com.vaadin:vaadin-client-compiler version 7.6.4
[ERROR] Mar 22, 2016 10:22:43 AM java.util.prefs.WindowsPreferences <init>
[ERROR] WARNUNG: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
[INFO] Compiling module net.gtidev.test.components.TestWidgetset
[INFO]    Computing all possible rebind results for 'com.vaadin.client.metadata.ConnectorBundleLoader'
[INFO]       Rebinding com.vaadin.client.metadata.ConnectorBundleLoader
[INFO]          Invoking generator com.vaadin.server.widgetsetutils.ConnectorBundleLoaderFactory
[INFO]             Populating eager bundle

. . . . . 250 more lines

[INFO]    Computing all possible rebind results for 'com.vaadin.client.ui.dd.VAcceptCriterionFactory'
[INFO]       Rebinding com.vaadin.client.ui.dd.VAcceptCriterionFactory
[INFO]          Invoking generator com.vaadin.server.widgetsetutils.AcceptCriteriaFactoryGenerator
[INFO]             Detecting available criteria ...
[INFO]             creating mapping for com.vaadin.event.dd.acceptcriteria.AcceptAll
[INFO]             creating mapping for com.vaadin.event.dd.acceptcriteria.And
[INFO]             creating mapping for com.vaadin.event.dd.acceptcriteria.ContainsDataFlavor
[INFO]             creating mapping for com.vaadin.event.dd.acceptcriteria.SourceIs
[INFO]             creating mapping for com.vaadin.ui.AbstractSelect.TargetItemIs
[INFO]             creating mapping for com.vaadin.ui.AbstractSelect.AcceptItem
[INFO]             creating mapping for com.vaadin.ui.Table.TableDropCriterion
[INFO]             creating mapping for com.vaadin.ui.Tree.TreeDropCriterion
[INFO]             creating mapping for com.vaadin.event.dd.acceptcriteria.Not
[INFO]             creating mapping for com.vaadin.event.dd.acceptcriteria.Or
[INFO]             creating mapping for com.vaadin.event.dd.acceptcriteria.ServerSideCriterion
[INFO]             creating mapping for com.vaadin.event.dd.acceptcriteria.SourceIsTarget
[INFO]             creating mapping for com.vaadin.event.dd.acceptcriteria.TargetDetailIs
[INFO]             creating mapping for com.vaadin.ui.Tree.TargetInSubtree
[INFO]             Done. (0seconds)
[INFO]    Compiling 1 permutation
[INFO]       Compiling permutation 0...
[INFO]    Compile of permutations succeeded
[INFO]    Compilation succeeded -- 59,217s
[INFO] Linking into C:\projects\misc\vaadin-boot\target\vaadin-boot-0.0.1-SNAPSHOT\net.gtidev.test.components.TestWidgetset
[INFO]    Link succeeded
[INFO]    Linking succeeded -- 0,492s

我用于自定义组件的文件是由 vaadin 7 项目中的 eclipse vaadin 插件生成的,我仅为此目的创建了该项目。当我在 eclipse 中启动这个 vaadin 7 项目时,该组件工作了。然后,我将这些文件复制到我的 spring boot maven 项目中,其中自定义组件不再加载。

我知道 Spring Boot 应用程序的引导机制和布局与“经典”Web 应用程序略有不同,并且静态资源不是从 webapp 文件夹加载,而是从 classpath:/static 文件夹加载。我认为问题的核心与这个事实有关,但我不知道该如何解决它。

我的插件配置(我尝试过使用和不使用注释选项):

<plugin>
  <groupId>com.vaadin</groupId>
  <artifactId>vaadin-maven-plugin</artifactId>
  <version>7.6.4</version>
  <configuration>
    <strict>true</strict>
    <force>true</force>
    <!-- Enable during development to speed compiling. -->
    <!-- <draftCompile>true</draftCompile>
    <style>DETAILED</style> -->
    <!-- End development options -->
    <!--<webappDirectory>src/main/webapp/VAADIN/widgetsets</webappDirectory>-->
    <modules>
      <module>net.gtidev.test.components.TestWidgetset</module>
    </modules>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>resources</goal>
        <goal>compile</goal>
      </goals>
    </execution>
  </executions>
</plugin>

我尝试了不同的 Maven 插件组合和配置。在一个示例中,还提到了一个 Google-GWT 插件,但在代码上运行此插件会产生与 vaadin 插件相同的日志输出:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>gwt-maven-plugin</artifactId>
  <version>2.5.1</version>
  <!--<configuration>-->
  <!--<webappDirectory>src/main/webapp/VAADIN/widgetsets</webappDirectory>-->
  <!--<extraJvmArgs>-Xmx512M -Xss1024k</extraJvmArgs>-->
  <!--<runTarget>clean</runTarget>-->
  <!--<hostedWebapp>${project.build.directory}/${project.build.finalName}</hostedWebapp>-->
  <!--<noServer>true</noServer>-->
  <!--<port>8080</port>-->
  <!--<soycDetailed>false</soycDetailed>-->
  <!--</configuration>-->
  <executions>
    <execution>
      <goals>
        <goal>resources</goal>
        <goal>compile</goal>
      </goals>
    </execution>
  </executions>
</plugin>

最佳答案

要使用自定义客户端扩展 Vaadin 附加组件,您需要将 vaadin-maven-plugin 添加到您的项目中。它将扫描您使用的附加组件,然后 GWT 为您的项目编译一个包含这些扩展的新小部件集。

如果您使用 start.spring.io 创建项目,则默认情况下,maven 插件不在您的项目中。例如使用此 Vaadin+Spring archetype 创建一个示例项目或基于官方 servlet 的原型(prototype),并将 vaadin-maven-plugin 相关部分从 pom.xml 复制到您的项目 pom.xml。然后进行完整的构建,一切都应该按预期工作。

关于maven - 使用 Maven 和 Spring Boot 的 Vaadin 自定义组件/小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36151204/

相关文章:

java - 尽管有 list ,但在 jar 文件中找不到主类

maven - 使用 POM 而不是命令行安装文件

java - 将 Javadoc 位置分配给 Eclipse 中的 maven 管理的依赖项,其中手动安装 Javadoc

java - 如何正确放大 Canvas ?

java - 响应中未显示 Spring Boot 验证错误消息

java - Apache Camel 返回带有转义字符的 JSON

java - Wildfly Swarm (Thorntail) 无法启动 - InvocationTargetException

java - GWT、Maven - 无法为对象堆保留足够的空间

java - 如何将所有日志输出写入文件spring boot

mysql - Hibernate+Gilead 应用程序中关联对象上的关系被删除