Vaadin - Spring Boot Application Not Compiling

541 Views Asked by At

I'm a Vaadin beginner. I tried to implement the code from a tutorial but my application could not compile. It's a simple spring boot application made up of three classes. The first class is the spring boot entry point, main class. The other two classes are the vaadin classes.

<?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 Class

@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 Layout Class

@SpringComponent
public class TodoLayout extends VerticalLayout {
}

Here is the server log

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

Thanks.

1

There are 1 best solutions below

0
On

Changing my IDE's java sdk to 8 solved the problem. Here is an excerpt from Henri Muurimaa:

"The server side aspects of Vaadin Framework work flawlessly with Java 9 today. If your app doesn’t use Vaadin add-ons, you can fire up your app on a Java 9 JVM and everything just works. However, if your app does use add-ons you will notice that compiling your widgetset is not yet supported with Java 9. The reason is a slight incompatibility between Java 9 and the GWT version we use to compile app-specific client side modifications into JavaScript. There is a fix but it has not landed in a release yet. We don’t want to depend on a snapshot, so we will release a maintenance version as soon as a fixed GWT release hits the internet. As a workaround, if you are using add-ons from Vaadin Directory, you can use our cloud service that will compile application widgetsets on demand. It is very easy to use, please see the blog post above for details and instructions."

Hence the vaadin-spring-boot-starter artifact might have compatiblity issues with Java 9.