java - 如何修复 'com.vaadin.DefaultWidgetSet' 不包含 com.vaadin.addon.charts.Chart 的实现

标签 java spring vaadin vaadin7

通过在 Eclipse/STS 中使用“Spring Stater Project”,我能够快速启动并运行 Vaadin 项目。我想通过 Vaadin-Addon 添加图表到项目中。我用谷歌搜索试图找到如何正确地添加和使用 Vaadin Chart 插件到项目中。但我很困惑,因为有这么多“指南/教程”,但很多不是针对 spring boot 的,或者它们已经过时或部分。

所以我正在寻找 Vaadin-SpringBoot-VaadinChart-AddOn 的完整指南/教程。

这是我目前所拥有的:

---- Pom文件----

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.aci</groupId>
    <artifactId>oversight2</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>oversight2</name>
    <description>Oversite</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.5.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
<!--        <dependency> -->
<!--            <groupId>com.vaadin</groupId> -->
<!--            <artifactId>vaadin-spring-boot</artifactId> -->
<!--            <version>1.0.0</version> -->
<!--        </dependency> -->

        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-spring-boot-starter</artifactId>
            <version>1.0.0.beta3</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.vaadin.addon</groupId>
            <version>2.0.0</version>
            <artifactId>vaadin-charts</artifactId>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-bom</artifactId>
                <version>7.4.5</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    <repositories>
        <repository>
            <id>vaadin-addons</id>
            <url>http://maven.vaadin.com/vaadin-addons</url>
        </repository>
    </repositories>

</project>

----Java代码----

public class BasicBarChart extends AbstractVaadinChartExample {

    @Override
    public String getDescription() {
        return "Basic bar";
    }

    @Override
    protected Component getChart() {
        Chart chart = new Chart(ChartType.BAR);

        Configuration conf = chart.getConfiguration();

        conf.setTitle("Historic World Population by Region");
        conf.setSubTitle("Source: Wikipedia.org");

        XAxis x = new XAxis();
        x.setCategories("Africa", "America", "Asia", "Europe", "Oceania");
        x.setTitle((String) null);
        conf.addxAxis(x);

        YAxis y = new YAxis();
        y.setMin(0);
        Title title = new Title("Population (millions)");
        title.setVerticalAlign(VerticalAlign.HIGH);
        y.setTitle(title);
        conf.addyAxis(y);

        Tooltip tooltip = new Tooltip();
        tooltip.setFormatter("this.series.name +': '+ this.y +' millions'");
        conf.setTooltip(tooltip);

        PlotOptionsBar plot = new PlotOptionsBar();
        plot.setDataLabels(new Labels(true));
        conf.setPlotOptions(plot);

        Legend legend = new Legend();
        legend.setLayout(LayoutDirection.VERTICAL);
        legend.setHorizontalAlign(HorizontalAlign.RIGHT);
        legend.setVerticalAlign(VerticalAlign.TOP);
        legend.setX(-100);
        legend.setY(100);
        legend.setFloating(true);
        legend.setBorderWidth(1);
        legend.setBackgroundColor("#FFFFFF");
        legend.setShadow(true);
        conf.setLegend(legend);

        conf.disableCredits();

        List series = new ArrayList();
        series.add(new ListSeries("Year 1800", 107, 31, 635, 203, 2));
        series.add(new ListSeries("Year 1900", 133, 156, 947, 408, 6));
        series.add(new ListSeries("Year 2008", 973, 914, 4054, 732, 34));
        conf.setSeries(series);

        chart.drawChart(conf);

        return chart;
    }
}

@SpringUI
@VaadinServletConfiguration(productionMode = false, ui = MyVaadinUI.class)
public class MyVaadinUI extends UI {
    @Override
    protected void init(VaadinRequest vaadinRequest) {
        setContent(new BasicBarChart());
    }
}

我已经创建了一个 30 天的 AGPL 许可证 key

有些网站说我需要一个 gwt.xml 文件,或者可以用注释来完成

一些网站说我需要“重新编译你的小部件集”,这意味着我需要在我的 pom 文件中添加一些插件。

其他网站说我需要一个 web.xml 但只需运行 spring-boot-vaadin Vaadin 应用程序即可。

当我运行代码时,我得到:

Widgetset 'com.vaadin.DefaultWidgetSet' does not contain implementation for com.vaadin.addon.charts.Chart. Check its component connector's @Connect mapping, widgetsets GWT module description file and re-compile your widgetset. In case you have downloaded a vaadin add-on package, you might want to refer to add-on instructions.

最佳答案

该过程与所有附加组件相同。对于简单的应用程序,您只需要核心小部件并且可以使用“DefaultWidgetSet”。您的项目需要“ApplicationWidgetset”,它将核心的基本客户端组件实现与您在项目中使用的所有附加组件相结合。

这些是使用 TouchKit 插件的示例说明,但过程基本相同:

关于java - 如何修复 'com.vaadin.DefaultWidgetSet' 不包含 com.vaadin.addon.charts.Chart 的实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33839831/

相关文章:

java - 如何在 Vaadin 10 中管理 session ?

css - Vaadin 14 Grid autoWidth with wrap content

java - ClassNotFoundException : spark. 从命令行运行时的请求

java - 插页式广告在实际测试中无法加载

java - 何时关闭 JNDI 上下文

java - SpringBoot RabbitMq解析盒子的json消息auto

java - Spring Boot 应用程序引擎日志格式不正确

spring - Spring MVC中的多 View 解析器

java - 如何将对象的 json 数组对象转换为该对象的 java 8 可选列表

java - ID 必须存在于容器中或作为生成的列,缺少 id : id