我設置了一個spring boot vaadin項目,並根據springs tutorial實現了這個類,但無法使用localhost:8080/ui訪問ui。我究竟做錯了什麼?Spring Boot和Vaadin UI無法訪問?
我的UI類:
package net.lawyd.server.ui;
import com.vaadin.annotations.Theme;
import com.vaadin.server.VaadinRequest;
import com.vaadin.spring.annotation.SpringUI;
import com.vaadin.ui.Button;
import com.vaadin.ui.Notification;
import com.vaadin.ui.UI;
@SpringUI(path = "/ui")
@Theme("valo")
public class VaadinUI extends UI {
@Override
protected void init(VaadinRequest request) {
setContent(new Button("Click me", e -> Notification.show("Hello Spring+Vaadin user!")));
}
}
這裏是我的Spring配置類:
package net.lawyd.server.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
@ComponentScan("net.lawyd.server")
@EnableJpaRepositories("net.lawyd.server")
@EnableTransactionManagement
public class SpringConfig {
// Nothing to do here
}
這裏是我的pom.xml:
<?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>net.lawyd</groupId>
<artifactId>lawyd-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
[更新1]我注意到了這一點日誌消息:
無法增強@Configuration bean定義 'com.vaadin.spring.VaadinConfiguration',因爲它的單例實例 已創建得太早。典型的原因是帶有BeanDefinitionRegistryPostProcessor返回類型的非靜態@Bean 方法: 考慮將這些方法聲明爲'static'。
[更新2]我使用start.spring.io創建了一個空的彈簧啓動應用程序,並插入了本教程中的演示。它在那裏工作,所以它必須是我的設置。
[更新3]我想通了,它有事情做與JerseyConfig,我把它當了它Vaadin工作,但球衣沒有了:
@SpringBootConfiguration
public class JerseyConfig extends ResourceConfig {
public JerseyConfig() {
register(TodoResource.class);
register(HealthResource.class);
}
}
這裏也是code on github。
我也試過'@ EnableVaadin'在這沒有什麼區別的SpringConfig。還嘗試訪問localhost:8080下的根目錄,但沒有任何結果。 –
您是否使用「mvn spring-boot:run」開始項目? – kometen
沒有任何區別。 –