我是Vaadin的初学者。我试图从教程中实现代码,但我的应用程序无法编译。它是一个由三个类组成的简单弹簧启动应用程序。第一类是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 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布局类
@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
感谢。
答案 0 :(得分:0)
将我的IDE的java sdk更改为8解决了这个问题。以下摘自Henri Muurimaa:
&#34; Vaadin Framework的服务器端方面今天与Java 9完美配合。如果您的应用程序不使用Vaadin附加组件,您可以在Java 9 JVM上启动您的应用程序,一切正常。 但是,如果您的应用程序确实使用了附加组件,您会注意到Java 9尚不支持编译您的widgetset。原因是Java 9和我们用于将特定于应用程序的客户端修改编译为JavaScript的GWT版本之间存在轻微的不兼容性。有一个修复但它还没有登陆版本。我们不想依赖快照,所以一旦固定的GWT版本上网,我们就会发布维护版本。 作为解决方法,如果您使用Vaadin Directory中的附加组件,则可以使用我们的云服务,该服务将按需编译应用程序小部件集。它非常易于使用,请参阅上面的博客文章了解详细信息和说明。&#34;
因此vaadin-spring-boot-starter artifact可能与Java 9存在兼容性问题。