我对vaadin相对较新,并开始使用spring启动应用程序和vaadin spring启动插件。一切工作正常,直到我试图创建我自己的组件/小部件。Vaadin自定义组件/小工具Maven和Spring启动
不幸的是,我没有找到任何“官方”的例子/文档如何设置春季启动应用程序中的自定义组件,所以我不得不搜索网络,找出如何在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引导应用程序与“传统”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插件的组合和配置。举一个例子,也有一个谷歌,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 7中使用gwt-maven-plugin,在Vaadin 6系列中使用gwt-maven-plugin。我认为你的原始尝试几乎是正确的,只有引导不会查看src/main/webapp,因此需要进行配置。请参阅下面的答案。 – mstahv