0

我是 Vaadin 初学者。我尝试实现教程中的代码,但我的应用程序无法编译。这是一个简单的 Spring Boot 应用程序,由三个类组成。第一个类是spring boot的入口点,主类。其他两个类是 vaadin 类。

<?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.demo</groupId>
<artifactId>vaadin-tut</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>vaadin-tut</name>
<description>Demo project for Spring Boot</description>

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

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <vaadin.version>8.2.0</vaadin.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-bom</artifactId>
            <version>${vaadin.version}</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>

TodoUI 类

@SpringUI
public class TodoUI extends UI {

private VerticalLayout root;

@Autowired
private TodoLayout todoLayout;

@Override
protected void init(VaadinRequest vaadinRequest) {
    setLayout();
    addHeader();
    addForm();
    addTodoList();
    addDeleteButton();
}

private void setLayout() {
    root = new VerticalLayout();
    setContent(root);
}

private void addHeader() {
    root.addComponent(new Label("TODOs"));
}

private void addForm() {
    HorizontalLayout formLayout = new HorizontalLayout();
    TextField task = new TextField();
    Button add = new Button("Add");
    formLayout.addComponents(task, add);
    root.addComponent(formLayout);
}

private void addTodoList() {
    root.addComponent(todoLayout);
}

private void addDeleteButton() {
    root.addComponent(new Button("Deleted Completed"));
}
}

ToDo 布局类

@SpringComponent
public class TodoLayout extends VerticalLayout {
}

这是服务器日志

Information:java: /root/.m2/repository/com/vaadin/vaadin-server/8.2.0/vaadin-server-8.2.0.jar(/com/vaadin/server/AbstractClientConnector.java) uses unchecked or unsafe operations.
Information:java: Recompile with -Xlint:unchecked for details.
Information:java: Errors occurred while compiling module 'vaadin-tut'
Information:javac 9.0.1 was used to compile java sources
Information:1/16/18 12:16 AM - Compilation completed with 2 errors and 6 warnings in 3s 1ms
Error:java: method <T>addAction(T) is already defined in interface com.vaadin.event.Action.Notifier
Error:java: method <T>removeAction(T) is already defined in interface com.vaadin.event.Action.Notifier
Warning:java: com.vaadin.ui.LegacyComponent in com.vaadin.ui has been deprecated
Warning:java: com.vaadin.server.LegacyCommunicationManager in com.vaadin.server has been deprecated
Warning:java: encodeState(com.vaadin.server.ClientConnector,com.vaadin.shared.communication.SharedState) in com.vaadin.server.LegacyCommunicationManager has been deprecated
Warning:java: createConnectorId(com.vaadin.server.ClientConnector) in com.vaadin.server.VaadinSession has been deprecated
Warning:java: removeListener(java.lang.Class<?>,java.lang.Object,java.lang.String) in com.vaadin.event.MethodEventSource has been deprecated
Warning:java: removeListener(java.lang.Class<?>,java.lang.Object,java.lang.reflect.Method) in com.vaadin.event.MethodEventSource has been deprecated

谢谢。

4

1 回答 1

0

将我的 IDE 的 java sdk 更改为 8 解决了这个问题。以下是Henri Muurimaa的摘录:

“如今,Vaadin 框架的服务器端方面与 Java 9 完美配合。如果您的应用程序不使用 Vaadin 插件,您可以在 Java 9 JVM 上启动您的应用程序,一切正常。但是,如果您的应用程序使用您会注意到 Java 9 尚不支持编译您的小部件集。原因是 Java 9 与我们用于将特定于应用程序的客户端修改编译为 JavaScript 的 GWT 版本之间略有不兼容。有一个修复程序,但它还没有发布。我们不想依赖快照,所以我们会在固定的 GWT 版本上线后立即发布维护版本。作为一种解决方法,如果您使用来自 Vaadin 的附加组件目录,您可以使用我们的云服务,它会按需编译应用程序小部件集。非常好用,有关详细信息和说明,请参阅上面的博客文章。”

因此,vaadin-spring-boot-starter 工件可能与 Java 9 存在兼容性问题。

于 2018-01-17T17:20:10.537 回答